static void test_iterator_whitespace(TestBatchRunner *runner) { int num_spaces; String *ws_smiley = S_smiley_with_whitespace(&num_spaces); { StringIterator *iter = Str_Top(ws_smiley); TEST_INT_EQ(runner, StrIter_Skip_Whitespace(iter), num_spaces, "Skip_Whitespace"); TEST_INT_EQ(runner, StrIter_Skip_Whitespace(iter), 0, "Skip_Whitespace without whitespace"); DECREF(iter); } { StringIterator *iter = Str_Tail(ws_smiley); TEST_INT_EQ(runner, StrIter_Skip_Whitespace_Back(iter), num_spaces, "Skip_Whitespace_Back"); TEST_INT_EQ(runner, StrIter_Skip_Whitespace_Back(iter), 0, "Skip_Whitespace_Back without whitespace"); DECREF(iter); } DECREF(ws_smiley); }
String* Str_Trim_IMP(String *self) { StringIterator *top = STACK_ITER(self, 0); StrIter_Skip_Whitespace(top); StringIterator *tail = NULL; if (top->byte_offset < self->size) { tail = STACK_ITER(self, self->size); StrIter_Skip_Whitespace_Back(tail); } return StrIter_crop((StringIterator*)top, (StringIterator*)tail); }
String* Str_Trim_Tail_IMP(String *self) { StringIterator *tail = STACK_ITER(self, self->size); StrIter_Skip_Whitespace_Back(tail); return StrIter_crop(NULL, (StringIterator*)tail); }