nginx开发_字符串操作函数
由于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开发_字符串操作函数的更多相关文章
- JavaScript中常见的字符串操作函数及用法
JavaScript中常见的字符串操作函数及用法 最近几次参加前端实习生招聘的笔试,发现很多笔试题都会考到字符串的处理,比方说去哪儿网笔试题.淘宝的笔试题等.如果你经常参加笔试或者也是一个过来人,相信 ...
- Sql字符串操作函数
1.去空格函数 (1).LTRIM() 把字符串头部的空格去掉. (2).RTRIM() 把字符串尾部的空格去掉. 2.字符转换函数(1).ASCII()返回字符表达式最左端字符的ASCII 码值.在 ...
- 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...
- C语言的常用字符串操作函数(一)
一直做的是单片机相关的程序设计,所以程序设计上更偏向底层,对于字符串的操作也仅限于液晶屏幕上的显示等工作,想提高下字符串操作的水平,而不是笨拙的数组替换等方式,翻看帖子发现C语言的字符串操作函数竟然这 ...
- linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words
1.1 字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...
- mysql常用字符串操作函数大全,以及实例
今天在论坛中看到一个关于mysql的问题,问题如下 good_id cat_id12654 665,56912655 601,4722 goods_id是商品i ...
- Postgresql 字符串操作函数
样例测试: update property set memorial_no = btrim(memorial_no, ' ') where memorial_no like ' %' 或:update ...
- LoadRunner中常用的字符串操作函数
LoadRunner中常用的字符串操作函数有: strcpy(destination_string, source_string); strc ...
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...
随机推荐
- 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告
2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...
- vue2.0 自定义 提示框(Toast)组件
1.自定义 提示框 组件 src / components / Toast / index.js /** * 自定义 提示框( Toast )组件 */ var Toast = {}; var sho ...
- sql分级汇总
--測试数据 create table tb([DB-ID] varchar(10),ENTITY varchar(10),DATE varchar(10),[CUST-NO] int,AMOUNT ...
- JSP技术基础(动态网页基础)
前言:如果说html为静态网页基础,那么jsp就是动态网页基础,两者的区别就是jsp在html的前面多加了几行而已.当然,jsp里面对java的支持度更高.要明白,js只是嵌入在客户端的小程序小脚本而 ...
- python 写数据到txt 文件
# coding=utf-8 import codecs # list = [[1,2],[3,4]] list = ['{"PN":"34VT123",&qu ...
- OcelotAPI 简单使用—服务发现、流控
我这人比较懒 直接上配置文件的图 其中serviceName是服务名称, LoadBalancer是负载均衡策略. 对于流控我为了做测试写的1s 限制5次请求. 剩下的看名字就OK了. 要使用服务发现 ...
- mysql 较为高效的分页
直接上代码 DaoImpl: /** * 开发转让页面展示 ,查询搜索数据,而且分页展示 * @param zrdp 搜索条件封装对象 * @return */ @SuppressWarnings(& ...
- 两个经典的文件IO程序示例
前言 本文分析两个经典的C++文件IO程序,提炼出其中文件IO的基本套路,留待日后查阅. 程序功能 程序一打印用户指定的所有文本文件,程序二向用户指定的所有文本文件中写入数据. 程序一代码及其注释 # ...
- NoSQL的四大类型
1 键值数据库 相关产品:Redis.Riak.SimpleDB.Chordless.Scalaris.Memcached 应用:内容缓存 优点:扩展性好.灵活性好.大量写操作时性能高 缺点:无法存储 ...
- EasyPusher手机直播编码推送之图像旋转90度后画面重复的问题
本文转自EasyDarwin开源团队开发Holo的博客:http://blog.csdn.net/holo_easydarwin 最初在做EasyPusher手机直播的时候遇到过一个问题:手机竖屏推送 ...