void String::trim_right(void) { if(length()) { str_trimright(sdata->chars); /* update length */ sdata->length = strlen(sdata->chars); } }
/* * scan section in [section] * returned value is terminated with '\0' */ static bool scan_section(char* line, char* buf, int bufsz) { char* bufp = buf; bool status = false; str_trimleft(line); for(; *line && bufsz > 0; line++) { if(*line == SECT_CLOSE) { status = true; break; } *bufp++ = *line; bufsz--; } *bufp = '\0'; str_trimright(buf); return status; }
UT_VERIFY( STR_EQUAL("XXX ABA BBCCBBC XXX !@# . ABB", str_toupper(s4)) ); char s5[] = " some with spaces"; UT_VERIFY( STR_EQUAL("some with spaces", str_trimleft(s5)) ); char s6[] = " some with spaces"; UT_VERIFY( STR_EQUAL("some with spaces", str_trimleft(s6)) ); char s6a[] = "| some with spaces"; UT_VERIFY( STR_EQUAL("| some with spaces", str_trimleft(s6a)) ); char s7[] = ". some with spaces"; UT_VERIFY( STR_EQUAL(". some with spaces", str_trimleft(s7)) ); char s8[] = "some with spaces "; UT_VERIFY( STR_EQUAL("some with spaces", str_trimright(s8)) ); char s9[] = "some with spaces |"; UT_VERIFY( STR_EQUAL("some with spaces |", str_trimright(s9)) ); char s10[] = "some without spaces"; UT_VERIFY( STR_EQUAL("some without spaces", str_trimright(s10)) ); char s11[] = "\t\t\t\t\tsome\tstring \t\t"; UT_VERIFY( STR_EQUAL("some\tstring", str_trim(s11)) ); char s12[] = "\nsss\n"; UT_VERIFY( STR_EQUAL("sss", str_trim(s12)) ); UT_VERIFY( str_ends("sample.png", ".png") == true ); UT_VERIFY( str_ends("sample", "foo") == false );