strtoupper():

 PHP_FUNCTION(strtoupper)
{
zend_string *str; ZEND_PARSE_PARAMETERS_START(, )
Z_PARAM_STR(str)
ZEND_PARSE_PARAMETERS_END(); RETURN_STR(php_string_toupper(str));
}

主要实现在 php_string_toupper()函数:

 PHPAPI zend_string *php_string_toupper(zend_string *s)
{
unsigned char *c, *e; c = (unsigned char *)ZSTR_VAL(s); //字符串首地址
e = c + ZSTR_LEN(s); // 字符串末尾之后的地址,指向字符串结束标志"\0" while (c < e) {
if (islower(*c)) { //遇到第一个小写字符,则进入此if分支,对之后字符的操作都将在此if中完成
register unsigned char *r;
zend_string *res = zend_string_alloc(ZSTR_LEN(s), ); //开辟内存存放zend_string类型数据 if (c != (unsigned char*)ZSTR_VAL(s)) { //c不是字符串首地址时,执行此if
memcpy(ZSTR_VAL(res), ZSTR_VAL(s), c - (unsigned char*)ZSTR_VAL(s)); //将c位置之前的字符数据复制给res
}
r = c + (ZSTR_VAL(res) - ZSTR_VAL(s)); // 开始进行转换的位置
// 下面的while中对每个字符都执行大写转换操作
while (c < e) {
*r = toupper(*c);
r++;
c++;
}
*r = '\0'; //为字符串添加结束标志
return res; //返回新字符串
}
c++;
}
return zend_string_copy(s); //原始字符串没有被操作,则返回原始字符串,并将引用+1
}

strtolower()与之类似。

php内置函数分析之strtoupper()、strtolower()的更多相关文章

  1. map内置函数分析所得到的思路

    map:会根据提供的函数对指定序列做映射. map(func, *iterables) --> map object Make an iterator that computes the fun ...

  2. php内置函数分析之array_diff_assoc()

    static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_type) /* {{{ */ { uint ...

  3. php内置函数分析之array_combine()

    PHP_FUNCTION(array_combine) { HashTable *values, *keys; uint32_t pos_values = ; zval *entry_keys, *e ...

  4. php内置函数分析之ucwords()

    PHP_FUNCTION(ucwords) { zend_string *str; char *delims = " \t\r\n\f\v"; register char *r, ...

  5. php内置函数分析之ucfirst()、lcfirst()

    ucfirst($str) 将 str 的首字符(如果首字符是字母)转换为大写字母,并返回这个字符串. 源码位于 ext/standard/string.c /* {{{ php_ucfirst Up ...

  6. php内置函数分析之trim()

    官方手册中: 类似函数还有两个:ltrim() 和 rtrim().分别处理字符串的左侧.右侧. trim()的具体实现位于:ext/standard/string.c /* {{{ proto st ...

  7. php内置函数分析之str_pad()

    PHP_FUNCTION(str_pad) { /* Input arguments */ zend_string *input; /* Input string 输入字符串*/ zend_long ...

  8. php内置函数分析之array_fill_keys()

    PHP_FUNCTION(array_fill_keys) { zval *keys, *val, *entry; if (zend_parse_parameters(ZEND_NUM_ARGS(), ...

  9. php内置函数分析range()

    PHP_FUNCTION(range) { zval *zlow, *zhigh, *zstep = NULL, tmp; , is_step_double = ; double step = 1.0 ...

随机推荐

  1. CruiseControl.NET配置

    CruiseControl.NET简介 CruiseControl.NET是.net平台下,一个开源的自动化持续集成工具. 它是一个程序套件,但其核心是一个叫做CruiseControl.NET Se ...

  2. 高清摄像头MIPI接口与ARM连接【转】

    本文转载自:http://www.cnblogs.com/whw19818/p/5811299.html MIPI摄像头常见于手机.平板中,支持500万像素以上高清分辨率.它的全称为“Mobile I ...

  3. 插桩 inline hook 动态二进制插桩的原理和基本实现过程

    插桩测试 https://source.android.google.cn/compatibility/tests/development/instrumentation https://zhuanl ...

  4. CyclicBarrier 源码分析

    CyclicBarrier CyclicBarrier 是一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point) 之后同时释放执行.CyclicB ...

  5. SpringBoot 切换国际化

    git:https://github.com/xiaozhuanfeng/demoProj 代码结构: application.properties: spring.messages.basename ...

  6. 006-spring-data-elasticsearch 3.0.0.0使用【四】-spring-data之Elasticsearch Repositories

    续 二.Elasticsearch Repositories 2.1.简介 2.1.1.Spring命名空间 Spring Data Elasticsearch模块包含一个允许定义存储库bean的自定 ...

  7. git总览

    git客户端官网:https://git-scm.com/ 下载对应版本安装 服务器安装git 安装依赖:yum install -y curl-devel expat-devel gettext-d ...

  8. Centos 下更改MySQL源数据存放目录(datadir)

    MySQL在安装完成之后,其源数据默认存放在 /var/lib/mysql/ 目录下,一般情况下,该目录在根目录下,由于Linux系统默认  根目录所在挂载的磁盘容量有限,随着生产数据的不断产生,该目 ...

  9. C++边双缩点,Redundant Paths 分离的路径

    一道比较简单的 关于边双的题,个人感觉难度不大. 求出整个图的边双,根据边双的定义我们可以延伸出 边双的任两个点都有至少两种路径来互相抵达(因为其不存在割边) .不妨将每个边双缩成一个点,样例中的图便 ...

  10. PHP的设计模式及场景应用介绍

    有大量的文章解释什么是设计模式,如何实现设计模式,网络上不需要再写一篇这样的文章.相反,在本文中我们更多的讨论什么时候用和为什么要用,而不是用哪一个和如何使用. 我将会为这些设计模式描绘不同的场景和案 ...