[C/C++]_[字符串处理]_[过滤出HTML标签的属性值]
2012-11-12 11:03
344 查看
typedef struct ElementAttribute ElementAttribute; struct ElementAttribute { const char* name; const char* value; ElementAttribute* previous; }; static const char* HtmlFindSpaceFromRecursion(const char* str, const char* start) { const char* p = str; while (p >= start) { if (*p == 0x20) { return p; } --p; } return str; } /** * 1.注意,这个函数只适合标准的属性格式,也就是"是成对存在. */ static ElementAttribute* HtmlGetElementAttribute(char* str) { ElementAttribute *attr = NULL; static char quote = '\"'; char* p = strchr(str, quote); while (p) { char *start = p; //属性名 char* a_name_start = (char*) HtmlFindSpaceFromRecursion(start, str); *(start - 1) = 0; //属性值 p = strchr(start + 1, quote); *p = 0; ElementAttribute *next = (ElementAttribute*) malloc( sizeof(ElementAttribute)); memset(next, 0, sizeof(ElementAttribute)); next->name = a_name_start + 1; next->value = start + 1; next->previous = attr; attr = next; p = strchr(p + 1, quote); } return attr; } TEST(main,testElementAttribute) { char* str = strdup("p height=\"1em\" width=\"0pt\" align=\"center\""); ElementAttribute* attr = HtmlGetElementAttribute(str); while(attr) { QXLOG("name: ",attr->name); QXLOG("value:",attr->value); attr = attr->previous; } free(str); }
相关文章推荐
- [C/C++]_[字符串处理]_[过滤出HTML标签的属性值]
- html标签title属性值包括<br/>处理
- asp.net 截取带有html标签的字符串(先过滤html,再截取)的方法
- js时间戳转换字符串,过滤html字符串标签
- 过滤网页中的HTML标签C++代码
- 使用Structs标签处理带有html标签元素的字符串
- iOS开发 字符串过滤html标签
- java后台过滤字符串中HTML标签和空格
- Objective c里字符串NSString 过滤HTML标签的两种方法
- smarty截取字符串与过滤HTML标签
- 过滤字符串中的html标签
- Ruby on Rails 项目里面字符串过滤html标签
- java过滤掉字符串中的html标签、style标签、script标签
- DEDE中如何过滤掉Html标签,并且截取字符串长度
- 过滤字符串html标签方法
- handlebars解决HTML escaping Html转义(解决那些标签需要作为html标签,哪些作为普通字符串处理)
- PHP函数:怎么去掉字符串和文本中的html标签&标识-字符串处理
- DEDE中如何过滤掉Html标签,并且截取字符串长度
- java使用正则表达式过滤掉字符串中的html标签