00001
00010 #include <GKlib.h>
00011
00012
00013
00015
00016 void test_strstr_replace()
00017 {
00018 char *new_str;
00019 int rc;
00020
00021 rc = gk_strstr_replace("This is a simple string", "s", "S", "", &new_str);
00022 printf("%d, %s.\n", rc, new_str);
00023 gk_free((void **)&new_str, LTERM);
00024
00025
00026 rc = gk_strstr_replace("This is a simple string", "s", "S", "g", &new_str);
00027 printf("%d, %s.\n", rc, new_str);
00028 gk_free((void **)&new_str, LTERM);
00029
00030
00031 rc = gk_strstr_replace("This is a simple SS & ss string", "s", "T", "g", &new_str);
00032 printf("%d, %s.\n", rc, new_str);
00033 gk_free((void **)&new_str, LTERM);
00034
00035
00036 rc = gk_strstr_replace("This is a simple SS & ss string", "s", "T", "ig", &new_str);
00037 printf("%d, %s.\n", rc, new_str);
00038 gk_free((void **)&new_str, LTERM);
00039
00040 rc = gk_strstr_replace("This is a simple SS & ss string", "\\b\\w(\\w+)\\w\\b", "$1", "ig", &new_str);
00041 printf("%d, %s.\n", rc, new_str);
00042 gk_free((void **)&new_str, LTERM);
00043
00044 rc = gk_strstr_replace("This is a simple SS & ss string", "\\b\\w+\\b", "word", "ig", &new_str);
00045 printf("%d, %s.\n", rc, new_str);
00046 gk_free((void **)&new_str, LTERM);
00047
00048 rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4",
00049 "(http://www\\.cs\\.umn\\.edu/)(.*)-T(\\d+)", "$1$2-P$3", "g", &new_str);
00050 printf("%d, %s.\n", rc, new_str);
00051 gk_free((void **)&new_str, LTERM);
00052
00053 rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4",
00054 "(\\d+)", "number:$1", "ig", &new_str);
00055 printf("%d, %s.\n", rc, new_str);
00056 gk_free((void **)&new_str, LTERM);
00057
00058
00059 rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4",
00060 "(http://www\\.cs\\.umn\\.edu/)", "[$1]", "g", &new_str);
00061 printf("%d, %s.\n", rc, new_str);
00062 gk_free((void **)&new_str, LTERM);
00063
00064
00065
00066 }
00067
00068
00069
00070 int main()
00071 {
00072 test_strstr_replace();
00073
00074
00075
00076
00077
00078
00079
00080
00081 }
00082