} END_TEST START_TEST(test_strings_replace_substrings_invalid) { fail_unless(replace_substring(NULL, NULL, NULL) == NULL); fail_unless(replace_substring("", NULL, NULL) == NULL); fail_unless(replace_substring("", "", NULL) == NULL); } END_TEST
} END_TEST START_TEST(test_strings_replace_substrings_3) { char* result = replace_substring("test", "e", "fg"); fail_unless(result != NULL); fail_unless(strncmp(result, "tfgst", 6) == 0); g_free(result); } END_TEST
char * markup_text (char *source) { char *str1, *str2; str1 = source; str2 = replace_substring (str1, "&", "&"); str1 = replace_substring (str2, "<", "<"); g_free (str2); str2 = replace_substring (str1, ">", ">"); g_free (str1); str1 = replace_substring (str2, """, "\""); g_free (str2); str2 = replace_substring (str1, "'", "\'"); g_free (str1); return str2; }
bool cmd_exec(girara_session_t* session, girara_list_t* argument_list) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; if (zathura->document != NULL) { const char* path = zathura_document_get_path(zathura->document); GIRARA_LIST_FOREACH(argument_list, char*, iter, value) char* r = NULL; if ((r = replace_substring(value, "$FILE", path)) != NULL) { girara_list_iterator_set(iter, r); } GIRARA_LIST_FOREACH_END(argument_list, char*, iter, value); } return girara_exec_with_argument_list(session, argument_list); }
std::string Creature::replace_with_npc_name( std::string input ) const { replace_substring( input, "<npcname>", disp_name(), true ); return input; }
} END_TEST START_TEST(test_strings_replace_substrings_nothing_to_replace) { fail_unless(replace_substring("test", "n", "y") == NULL); } END_TEST
replace(PyStringObject *self, const char *from_s, Py_ssize_t from_len, const char *to_s, Py_ssize_t to_len, Py_ssize_t maxcount) { if (maxcount < 0) { maxcount = PY_SSIZE_T_MAX; } else if (maxcount == 0 || PyString_GET_SIZE(self) == 0) { /* nothing to do; return the original string */ return return_self(self); } if (maxcount == 0 || (from_len == 0 && to_len == 0)) { /* nothing to do; return the original string */ return return_self(self); } /* Handle zero-length special cases */ if (from_len == 0) { /* insert the 'to' string everywhere. */ /* >>> "Python".replace("", ".") */ /* '.P.y.t.h.o.n.' */ return replace_interleave(self, to_s, to_len, maxcount); } /* Except for "".replace("", "A") == "A" there is no way beyond this */ /* point for an empty self string to generate a non-empty string */ /* Special case so the remaining code always gets a non-empty string */ if (PyString_GET_SIZE(self) == 0) { return return_self(self); } if (to_len == 0) { /* delete all occurances of 'from' string */ if (from_len == 1) { return replace_delete_single_character( self, from_s[0], maxcount); } else { return replace_delete_substring(self, from_s, from_len, maxcount); } } /* Handle special case where both strings have the same length */ if (from_len == to_len) { if (from_len == 1) { return replace_single_character_in_place( self, from_s[0], to_s[0], maxcount); } else { return replace_substring_in_place( self, from_s, from_len, to_s, to_len, maxcount); } } /* Otherwise use the more generic algorithms */ if (from_len == 1) { return replace_single_character(self, from_s[0], to_s, to_len, maxcount); } else { /* len('from')>=2, len('to')>=1 */ return replace_substring(self, from_s, from_len, to_s, to_len, maxcount); } }
int main(int argc, char **argv) { STARTUPINFO si; PROCESS_INFORMATION pi; unsigned short rc; char *new_at_file; char *old_at_file; char *line; int i; DWORD exitCode; if (argc<3 || argv[1][0] != '-' || (argv[1][1] != 'c' && argv[1][1] != 'm')) { fprintf(stderr, "Usage: fixpath -c|m<path@path@...> /cygdrive/c/WINDOWS/notepad.exe /cygdrive/c/x/test.txt\n"); exit(0); } if (getenv("DEBUG_FIXPATH") != NULL) { fprintf(stderr, "fixpath input line >%s<\n", strstr(GetCommandLine(), argv[1])); } if (argv[1][1] == 'c' && argv[1][2] == '\0') { if (getenv("DEBUG_FIXPATH") != NULL) { fprintf(stderr, "using cygwin mode\n"); } replace_cygdrive = replace_cygdrive_cygwin; } else if (argv[1][1] == 'm') { if (getenv("DEBUG_FIXPATH") != NULL) { fprintf(stderr, "using msys mode, with path list: %s\n", &argv[1][2]); } setup_msys_path_list(argv[1]); replace_cygdrive = replace_cygdrive_msys; } else { fprintf(stderr, "Unknown mode: %s\n", argv[1]); exit(-1); } line = replace_cygdrive(strstr(GetCommandLine(), argv[2])); for (i=1; i<argc; ++i) { if (argv[i][0] == '@') { // Found at-file! Fix it! old_at_file = replace_cygdrive(argv[i]); new_at_file = fix_at_file(old_at_file); line = replace_substring(line, old_at_file, new_at_file); } } if (getenv("DEBUG_FIXPATH") != NULL) { fprintf(stderr, "fixpath converted line >%s<\n", line); } ZeroMemory(&si,sizeof(si)); si.cb=sizeof(si); ZeroMemory(&pi,sizeof(pi)); rc = CreateProcess(NULL, line, 0, 0, TRUE, 0, 0, 0, &si, &pi); if(!rc) { // Could not start process for some reason. Try to report why: report_error(); exit(rc); } WaitForSingleObject(pi.hProcess,INFINITE); GetExitCodeProcess(pi.hProcess,&exitCode); if (getenv("DEBUG_FIXPATH") != NULL) { for (i=0; i<num_files_to_delete; ++i) { fprintf(stderr, "Not deleting temporary fixpath file %s\n", files_to_delete[i]); } } else { for (i=0; i<num_files_to_delete; ++i) { remove(files_to_delete[i]); } } exit(exitCode); }