darwin源码一些小问题

白杨先生 2014-07-18 09:40:36

darwin streaming server 5.5.5 源码中,StrPtrLen.cpp文件下PrintStrEOL()函数定义:





void StrPtrLen::PrintStrEOL(char* stopStr, char *appendStr)
{


char *thestr = GetAsCString();

SInt32 i = 0;
for (; i < (SInt32) Len; i ++) //for循环,保留thestr中没有被禁止打印的字符
{
if (StrPtrLen::sNonPrintChars[Ptr[i]])
{ thestr[i] = 0;
break;
}

}

for (i = 0; thestr[i] != 0 ; i ++)
{
if (thestr[i] == '%' && thestr[i+1] != '%' )
{ thestr[i] = '$';
}
} //单"%"转"$",这步处理这是为什么呢?

SInt32 stopLen = 0;
if (stopStr != NULL)
stopLen = ::strlen(stopStr);

if (stopLen > 0 && stopLen <= i)
{
char* stopPtr = ::strstr(thestr, stopStr);//搜索stopStr在theStr中的第一次出现。找到所搜索的字符串则返回字符串的地址。
if (stopPtr != NULL)
{ stopPtr += stopLen;
*stopPtr = 0;
i = stopPtr - thestr;
}
}

char * theStrLine = thestr;
char * nextLine = NULL;
char * theChar = NULL;
static char *cr="\\r";
static char *lf="\\n\n";
SInt32 tempLen = i;
for (i = 0; i < tempLen; i ++)
{
if (theStrLine[i] == '\r')
{ theChar = cr;
theStrLine[i] = 0;
nextLine = &theStrLine[i+1];
}
else if (theStrLine[i] == '\n')
{ theChar = lf;
theStrLine[i] = 0;
nextLine = &theStrLine[i+1];
}

if (nextLine != NULL)
{
qtss_printf(theStrLine);
qtss_printf(theChar);

theStrLine = nextLine;
nextLine = NULL;
tempLen -= (i+1);
i = -1;
}
}
qtss_printf(theStrLine);
delete thestr;

if (appendStr != NULL)
qtss_printf(appendStr);

}


一下代码段做这样一个单"%"转“$”有什么意义呢:

for (i = 0; thestr[i] != 0 ; i ++) 
{
if (thestr[i] == '%' && thestr[i+1] != '%' )
{ thestr[i] = '$';
}
}
...全文
6573 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

934

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计/Flash/Silverlight 开发 交互式设计
社区管理员
  • 交互式设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧