由于ngx_str_t为非NULL结尾的函数,且网络请求中有大量忽略大小写的需求,所以nginx内部封装了许多字符串操作相关的函数,函数名称极其相识,且使用时有有些约定,特此整理。

赋值&拷贝

#define ngx_string(str)        { sizeof(str) - 1, (u_char *) str }
#define ngx_null_string { 0, NULL }
#define ngx_str_set(str, text) (str)->len = sizeof(text) - 1; (str)->data = (u_char *) text
#define ngx_str_null(str) (str)->len = 0; (str)->data = NULL
//ngx_string与ngx_null_string常用于变量初始化
//ngx_str_set与ngx_str_null常用于变量赋值 #define ngx_memzero(buf, n) (void) memset(buf, 0, n)
#define ngx_memset(buf, c, n) (void) memset(buf, c, n) #define ngx_memcpy(dst, src, n) (void) memcpy(dst, src, n)
#define ngx_cpymem(dst, src, n) (((u_char *) memcpy(dst, src, n)) + (n))
#define ngx_copy ngx_cpymem
//ngx_cpymem返回dst的结尾位置 #define ngx_memmove(dst, src, n) (void) memmove(dst, src, n)
#define ngx_movemem(dst, src, n) (((u_char *) memmove(dst, src, n)) + (n))
//ngx_movemem返回dst的结尾位置 u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
//字符串赋值,且dst为NULL结尾
u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src);
//从pool内申请空间,并使用src赋值,不保证NULL结尾

字符串长度

#define ngx_strlen(s)       strlen((const char *) s)
size_t ngx_strnlen(u_char *p, size_t n);
//返回第一个'\0'或者n

大小写转换

#define ngx_tolower(c)      (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
#define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c) void ngx_strlow(u_char *dst, u_char *src, size_t n);

字符串比对

#define ngx_strncmp(s1, s2, n)  strncmp((const char *) s1, (const char *) s2, n)
//调用前需要保证s1与s2长度一致
#define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2)
//s1与s2都需要NULL结尾
ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
//调用前需要保证s1与s2长度一致,使用较少,常用ngx_strncmp #define ngx_memcmp(s1, s2, n) memcmp((const char *) s1, (const char *) s2, n) ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2);
//忽略大小写比对,s1需要NULL结尾,调用前需要保证s1与s2长度一致
ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n);
//忽略大小写比对,调用前需要保证s1与s2长度一致
ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
//忽略大小写比对,调用前需要保证s1与s2长度一致
ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
//内部判断长度相等
ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
//忽略大小写比对,且忽略最后的'.'字符
ngx_int_t ngx_filename_cmp(u_char *s1, u_char *s2, size_t n);
//根据操作系统,选择是否忽略大小写,且忽略最后的'/'字符

字符串搜索

#define ngx_strchr(s1, c)   strchr((const char *) s1, (int) c)
//字符搜索s1默认NULL结尾
static ngx_inline u_char * ngx_strlchr(u_char *p, u_char *last, u_char c);
//字符搜索
u_char *ngx_strnstr(u_char *s1, char *s2, size_t n);
//在s1中搜索子串s2,s2需要NULL结尾,n为s1长度
u_char *ngx_strstrn(u_char *s1, char *s2, size_t n);
//在s1中搜索子串s2,s1需要NULL结尾,n为s2长度-1
u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n);
//忽略大小写,在s1中搜索子串s2,s1需要NULL结尾,n为s2长度-1
u_char *ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n);
//忽略大小写,在[s1,last]中搜索子串s2,n为s2长度-1

字符串格式化

u_char * ngx_cdecl ngx_sprintf(u_char *buf, const char *fmt, ...);
//字符串格式化,外部保证buf大小
u_char * ngx_cdecl ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
u_char * ngx_cdecl ngx_slprintf(u_char *buf, u_char *last, const char *fmt, ...);
u_char *ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args);
//ngx_sprintf、ngx_snprintf、ngx_slprintf的内部函数,用于不定长参数的函数使用

字符串/数字转换

ngx_int_t ngx_atoi(u_char *line, size_t n);
ngx_int_t ngx_atofp(u_char *line, size_t n, size_t point);
ssize_t ngx_atosz(u_char *line, size_t n);
off_t ngx_atoof(u_char *line, size_t n);
time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);
u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);

字符串编解码

#define ngx_base64_encoded_length(len)  (((len + 2) / 3) * 4)
#define ngx_base64_decoded_length(len) (((len + 3) / 4) * 3)
void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
void ngx_encode_base64url(ngx_str_t *dst, ngx_str_t *src);
ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
ngx_int_t ngx_decode_base64url(ngx_str_t *dst, ngx_str_t *src); uint32_t ngx_utf8_decode(u_char **p, size_t n);
size_t ngx_utf8_length(u_char *p, size_t n);
u_char *ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len); uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type);
void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
uintptr_t ngx_escape_html(u_char *dst, u_char *src, size_t size);
uintptr_t ngx_escape_json(u_char *dst, u_char *src, size_t size);

nginx开发_字符串操作函数的更多相关文章

  1. JavaScript中常见的字符串操作函数及用法

    JavaScript中常见的字符串操作函数及用法 最近几次参加前端实习生招聘的笔试,发现很多笔试题都会考到字符串的处理,比方说去哪儿网笔试题.淘宝的笔试题等.如果你经常参加笔试或者也是一个过来人,相信 ...

  2. Sql字符串操作函数

    1.去空格函数 (1).LTRIM() 把字符串头部的空格去掉. (2).RTRIM() 把字符串尾部的空格去掉. 2.字符转换函数(1).ASCII()返回字符表达式最左端字符的ASCII 码值.在 ...

  3. 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...

  4. C语言的常用字符串操作函数(一)

    一直做的是单片机相关的程序设计,所以程序设计上更偏向底层,对于字符串的操作也仅限于液晶屏幕上的显示等工作,想提高下字符串操作的水平,而不是笨拙的数组替换等方式,翻看帖子发现C语言的字符串操作函数竟然这 ...

  5. linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words

    1.1       字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...

  6. mysql常用字符串操作函数大全,以及实例

    今天在论坛中看到一个关于mysql的问题,问题如下 good_id     cat_id12654         665,56912655         601,4722 goods_id是商品i ...

  7. Postgresql 字符串操作函数

    样例测试: update property set memorial_no = btrim(memorial_no, ' ') where memorial_no like ' %' 或:update ...

  8. LoadRunner中常用的字符串操作函数

    LoadRunner中常用的字符串操作函数有:                strcpy(destination_string, source_string);               strc ...

  9. C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...

随机推荐

  1. mac apache配置虚拟主机

    设置虚拟主机 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件 在httpd.conf中找到“#Include /private/etc/apac ...

  2. POJ3592 Instantaneous Transference 强连通+最长路

    题目链接: id=3592">poj3592 题意: 给出一幅n X m的二维地图,每一个格子可能是矿区,障碍,或者传送点 用不同的字符表示: 有一辆矿车从地图的左上角(0,0)出发, ...

  3. Android - Activity定制横屏(landscape)显示

    Activity定制横屏(landscape)显示 本文地址: http://blog.csdn.net/caroline_wendy Android横屏(landscape)显示:  android ...

  4. 开关电路_MOS和三极管

    https://blog.csdn.net/acelit/article/details/70171312 绍过一般的电源开关电路,控制电源的目的是省电,控制静态电流.不过以下的电路存在着几个缺点:  ...

  5. ECharts整合HT&#160;for&#160;Web的网络拓扑图应用

    ECharts图形组件在1.0公布的时候我就已经有所关注.今天在做项目的时候遇到了图标的需求,在HTfor Web上也有图形组件的功能.可是在尝试了下详细实现后,发现HT for Web的图形组件是以 ...

  6. Machine Learning:Neural Network---Representation

    Machine Learning:Neural Network---Representation 1.Non-Linear Classification 假设还採取简单的线性分类手段.那么会面临着过拟 ...

  7. Vue 资源

    一. 资源教程 综合类 vuejs 英文资料 Vue中文资料总汇 Vue.js 的一些资源索引 vue资料 入门类 vue 快速入门 Vue.js 中文系列视频教程 on Laravist 英文教程 ...

  8. 下载与安装---tensorflow on linux

    http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html 你可以使用我们提供的 Pip, Docker, ...

  9. python pyinotify模块详解

    转载于http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=23504396&id=2929446 1年多前就看过相关内容了, ...

  10. 调用Camera返回为空的分析及处理方法

    前言 大家可能遇到了这种情况.调用Camera,然后指定自己定义的保存路径,结果返回的Intent为空.我们来分析一下原因. 分析 首先看Camera的部分逻辑,在源代码中的Camera.java的d ...