X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=ccd7739c647b87d989b9cbc867810d915839770c;hp=44d325e072df297eb80977d1f03abd45af6bd543;hb=c9b92e317e7426db24fce2636134e1e46eb05d40;hpb=84b708489d9ca5d68ec516c2b30473ab75807fb4 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)