php mysql 字符串处理_MySQL 之动态字符串处理

/*

Concatenates any number of strings, escapes any OS quote in the result then

surround the whole affair in another set of quotes which is finally appended

to specified DYNAMIC_STRING. This function is especially useful when

building strings to be executed with the system() function.

@param str Dynamic String which will have addtional strings appended.

@param append String to be appended.

@param ... Optional. Additional string(s) to be appended.

@note The final argument in the list must be NullS even if no additional

options are passed.

@return True = Success.

*/

my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append, ...)

{

const char *quote_str= "\'";

const uint quote_len= 1;

my_bool ret= TRUE;

va_list dirty_text;

ret&= dynstr_append_mem(str, quote_str, quote_len); /* Leading quote */

va_start(dirty_text, append);

while (append != NullS)

{

const char *cur_pos= append;

const char *next_pos= cur_pos;

/* Search for quote in each string and replace with escaped quote */

while(*(next_pos= strcend(cur_pos, quote_str[0])) != '\0')

{

ret&= dynstr_append_mem(str, cur_pos, (uint) (next_pos - cur_pos));

ret&= dynstr_append_mem(str ,"\\", 1);

ret&= dynstr_append_mem(str, quote_str, quote_len);

cur_pos= next_pos + 1;

}

ret&= dynstr_append_mem(str, cur_pos, (uint) (next_pos - cur_pos));

append= va_arg(dirty_text, char *);

}

va_end(dirty_text);

ret&= dynstr_append_mem(str, quote_str, quote_len); /* Trailing quote */

return ret;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值