static void test_string_trim_right() { char *string; string = string_duplicate("Hola"); string_trim_right(&string); CU_ASSERT_STRING_EQUAL(string, "Hola"); free(string); string = string_duplicate("Hola "); string_trim_right(&string); CU_ASSERT_STRING_EQUAL(string, "Hola"); free(string); }
/* METHOD: diffNoSpace * ARGS: student: the student generated output file contents as a string * instructor: the instructor expected output file contents as a string * RETURN: Change: The difference of the two strings * PURPOSE: diffNoSpace is a helper function to the diffLineNoSpace function. * diffNoSpace does a per character comparison not including white space but * including new lines. The strings are not changed in this comparison. Runs * in linear time with respect to the longer string. */ Change diffNoSpace ( const std::string& _student, const std::string& _instructor ) { Change differences; differences.a_start = 0; differences.b_start = 0; std::string student = string_trim_right( _student ); std::string instructor = string_trim_right( _instructor ); unsigned int i = 0; unsigned int j = 0; while ( i != student.size() && j != instructor.size() ) { if ( student[i] == ' ' ) { i++; continue; } if ( instructor[j] == ' ' ) { j++; continue; } if ( student[i] != instructor[j] ) { differences.a_changes.push_back( i ); differences.b_changes.push_back( j ); } i++; j++; } while ( i != student.size() ) { if ( student[i] != ' ' ) differences.a_changes.push_back( i ); i++; } while ( j != instructor.size() ) { if ( instructor[j] != ' ' ) differences.b_changes.push_back( j ); j++; } return differences; }
int main(int argc, char **argv) { char *src = NULL; char *module = NULL; char dst[256]; /* 去除字符串尾部的无效字符 */ printf("******************************\n"); src = "agege g egegge ge\t\n#\n"; module = "\t\n#"; dst[0] = '\0'; if (string_trim_right(src, dst, module) < 0) { printf("函数调用错误!\n"); exit(-1); } printf("源字符串:%s\n" "模式字符串:%s\n" "结果字符串:%s\n\n", src, module, dst); printf("******************************\n"); return 0; }
/** * @NAME: string_trim * @DESC: Remueve todos los caracteres * vacios de la derecha y la izquierda */ void string_trim(char** text) { string_trim_left(text); string_trim_right(text); }
static struct value *global_SCOPEcalein_trim_SPACEright_ARG(struct value *s) { string_trim_right(value_string_value(s)); value_remove_reference(s); return s; }