From 47d41c4f1e09368feac8667abc0cc43dff8b36e0 Mon Sep 17 00:00:00 2001 From: yirenyiai Date: Thu, 2 Apr 2015 00:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=20=3D=20?= =?UTF-8?q?=E5=8F=B7=E6=93=8D=E4=BD=9C=E7=AC=A6=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E5=96=84=E4=B8=80=E4=B8=8Btest=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- src/html5.cpp | 2 +- test/test.cpp | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 3fb0741..908c197 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ build/ *.exp *.opensdf *.suo +*.ilk # windows [Dd]ebug/ @@ -43,4 +44,5 @@ build/ [Bb]bin/ [Bb]oost/ lib/boost/* -*.ilk + + diff --git a/src/html5.cpp b/src/html5.cpp index 4310020..bb5e456 100644 --- a/src/html5.cpp +++ b/src/html5.cpp @@ -459,7 +459,7 @@ bool html::basic_selector::condition::operator()(const html::basic_dom if (it == d.attributes.end()) return false; if (matching_attr_operator == operator_string_equalityt()) - strcmp_ignore_case(it->second, matching_attr_value); + return strcmp_ignore_case(it->second, matching_attr_value); else if (matching_attr_operator == operator_string_contain()) { if (matching_attr_value == selector_empty_string()) return it->second.empty(); diff --git a/test/test.cpp b/test/test.cpp index 229a397..4e061bd 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -6,6 +6,8 @@ const char msg_usage[] = "\nusage : %s \n\n"; + +// 如果你不希望跑命令行解析。那么你可以直接调用这个函数跑一下。 void test(); @@ -15,7 +17,6 @@ void callback(std::shared_ptr) int main(int argc, char *argv[]) { - test(); if (argc < 3) { if (argc > 0) @@ -60,14 +61,22 @@ void test() html::dom page_href_http_node; page.append_partial_html(""); - page.append_partial_html("hello world</title"); + page.append_partial_html("<title id=\"id_test\" href=\"http://www.baidu.com\" bkcolor=\"ff000000\" textcolor=\"ffffffff\">hello world</title"); page.append_partial_html("></head></html>"); - //page["[href='#']"]; - //page["[href!='#']"]; + page = page["#id_test"]; + printf("value : %s \n", page.to_plain_text().c_str()); + + page["[href]"]; + printf("value : %s \n", page.to_plain_text().c_str()); page = page["[href$='http']"]; + printf("value : %s \n", page.to_plain_text().c_str()); + + page = page["[bkcolor='ff000000']"]; + printf("value : %s \n", page.to_plain_text().c_str()); + page = page["[textcolor!='ff000000']"]; printf("value : %s \n", page.to_plain_text().c_str()); }