search_test.cpp File Reference

#include <stdio.h>
#include "text_model.h"
Include dependency graph for search_test.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 60 of file search_test.cpp.

References conv, text::Range::end, text::Position::offset, text::TextModel::open(), text::Position::paragraph, and text::Range::start.

00061 {
00062     if (argc != 2)
00063     {
00064         fprintf(stderr, "Usage: %s <file_name>.\n", argv[0]);
00065         return -1;
00066     }
00067 
00068     TextModel model(argv[1]);
00069     model.open();
00070     model.read_text();
00071 
00072     // Set search criteria.
00073     const char* search_text = "¹ùÐ¥Ìì";
00074     Position from(16, 0);
00075     bool case_sensitive = false;
00076     bool forward = false;
00077     bool match_whole_word = false;
00078 
00079     // Convert the search text to UTF-8 encoded string.
00080     const char* in_p = search_text;
00081     size_t in_bytes_left = strlen(search_text);
00082     char out_buf[1024];
00083     char *out_p = out_buf;
00084     size_t out_bytes_left = sizeof(out_buf);
00085 
00086     iconv_t conv = iconv_open("UTF-8", "GB2312");
00087     iconv(conv, &in_p, &in_bytes_left, &out_p, &out_bytes_left);
00088     iconv_close(conv);
00089 
00090     *out_p = 0;
00091 
00092     // Test search all function
00093     /*
00094     std::vector<Range> result_ranges;
00095     model.search_all(result_ranges, out_buf, case_sensitive, match_whole_word);
00096     for (unsigned int i=0; i<result_ranges.size(); i++)
00097     {
00098         printf("Match %d: (%d, %d) ~ (%d, %d)\n",
00099             i+1, 
00100             result_ranges[i].start.paragraph,
00101             result_ranges[i].start.offset,
00102             result_ranges[i].end.paragraph,
00103             result_ranges[i].end.offset);
00104     }*/
00105 
00106     // Test search next function.
00107     Range result;
00108     bool ret = model.search_next(result, from, out_buf, case_sensitive, forward, match_whole_word);
00109     if (ret == false)
00110     {
00111         printf("No match.\n");
00112     }
00113     else
00114     {
00115         printf("Pattern found: (%d, %d) ~ (%d, %d)\n",
00116             result.start.paragraph,
00117             result.start.offset,
00118             result.end.paragraph,
00119             result.end.offset);
00120     }
00121 
00122     getchar();
00123     return 0;
00124 }

Here is the call graph for this function:

Generated by  doxygen 1.6.2-20100208