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. ...
随机推荐
- DICOM:DICOM万能编辑工具之Sante DICOM Editor
版权声明:本文为zssure原创文章,转载请注明出处,未经允许不得转载. 目录(?)[-] 背景 DICOM Service的配置 Sante DICOM Editor自启动的服务 PACS查询下 ...
- 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 【转】
http://www.cnblogs.com/powertoolsteam/p/MVC_one.html 系列文章 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 七天学会A ...
- HttpClient获取Cookie的两种方式
转载:http://blog.csdn.net/zhangbinu/article/details/72777620 一.旧版本的HttpClient获取Cookies p.s. 该方式官方已不推荐使 ...
- 利用Python自动发送邮件
# -*- coding:utf-8 -*-from email.mime.text import MIMETextfrom email.header import Headerimport smtp ...
- 关于CUDA两种API:Runtime API 和 Driver API
CUDA 眼下有两种不同的 API:Runtime API 和 Driver API,两种 API 各有其适用的范围. 高级API(cuda_runtime.h)是一种C++ ...
- nodejs REPL(交互式解释器)
Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux ...
- 使用Python处理Excel文件的一些代码示例
笔记:使用Python处理Excel文件的一些代码示例,以下代码来自于<Python数据分析基础>一书,有删改 #!/usr/bin/env python3 # 导入读取Excel文件的库 ...
- Windows App开发之集合控件与数据绑定
为ListView和GridView加入数据 ListView採用垂直堆叠得方式显示数据.而GridView则採用水平堆叠得方式. 长相的话嘛,它们都几乎相同. <Grid Name=" ...
- PHP debug_backtrace() 函数
PHP Error 和 Logging 函数 实例 生成 PHP backtrace: <?php function a($txt) { b("Glenn"); } func ...
- MySQL 存储过程 (3)
以下介绍下像数据库循环插入数据操作 第一步:建立存储过程用到的信息表