X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=ccd7739c647b87d989b9cbc867810d915839770c;hb=0840b3d295d4c734eba359f91039a506b15c815f;hp=44d325e072df297eb80977d1f03abd45af6bd543;hpb=5c3291dc396b795696e94f47780308fd7ace6fc4;p=pspp-builds.git diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 44d325e0..ccd7739c 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -1071,6 +1071,34 @@ ds_set_length (struct string *st, size_t new_length, char pad) st->ss.length = new_length; } +/* Removes N characters from ST starting at offset START. */ +void +ds_remove (struct string *st, size_t start, size_t n) +{ + if (n > 0 && start < st->ss.length) + { + if (st->ss.length - start <= n) + { + /* All characters at or beyond START are deleted. */ + st->ss.length = start; + } + else + { + /* Some characters remain and must be shifted into + position. */ + memmove (st->ss.string + st->ss.length, + st->ss.string + st->ss.length + n, + st->ss.length - start - n); + st->ss.length -= n; + } + } + else + { + /* There are no characters to delete or no characters at or + beyond START, hence deletion is a no-op. */ + } +} + /* Returns true if ST is empty, false otherwise. */ bool ds_is_empty (const struct string *st)