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. ...
随机推荐
- 调用tf.softmax_cross_entropy_with_logits函数出错解决
原来这个函数,不能按以前的方式进行调用了,只能使用命名参数的方式来调用.原来是这样的: tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y ...
- 【OpenGL】OpenGL帧缓存对象(FBO:Frame Buffer Object) 【转】
http://blog.csdn.net/xiajun07061225/article/details/7283929/ OpenGL Frame BufferObject(FBO) Overview ...
- sqlite数据库改动及升级
今天是上班的第二天.听说我近期的任务就是改bug.唉,权当学习了,遇到的一些问题都记录下来. sqlite数据库是android中很经常使用的数据库.今天帮别人改bug,遇到一些问题记录下来. 1.改 ...
- opencv yuv420与Mat互转
项目用到opencv 融合图片的功能,经过一天的调试,达到预期目标,先将如何调用opencv库实现YUV42与Mat互转记录下来. 一.下载opencv编译的库下载地址是:http://opencv. ...
- VS2010配置QT5.5.0开发环境
一.官网下载QT和qtvsaddin插件 网址:http://www.qt.io/download-open-source/ 1. 2. 3. 得到下载的安装包,点击安装就能够了 watermark/ ...
- kubernetes对象之cronjob
系列目录 类似于Linux的Cron模块,CronJob用来运行定时性任务,或者周期性.重复性任务.注意CronJob启动的是kubernetes中的Job,不是ReplicaSet.DaemonSe ...
- kubernetes之故障排查和节点维护(二)
系列目录 案例现场: 测试环境集群本来正常,突然间歇性地出现服务不能正常访问,过一会儿刷新页面又可以正常访问了.进入到服务所在的pod查看输出日志并没有发现异常.使用kubectl get node命 ...
- js event 的target 和currentTarget
target 点击的实际tag currentTarget 绑定事件的target
- ipa验证错误问题总结
The following issues were found during validation.这个error的产生原因是因为代码中写的标示符或者方法名,与系统的命名空间冲突. 具体是哪个标示符或 ...
- 海康DS NVR播放URL规则
URL规定:rtsp://username:password@<address>:<port>/Streaming/Channels/<id>(?parm1=val ...