Now that it doesn't have to fit in with the multi-byte version's logic,
it can be re-structured to be simpler. No functional change intended.
static void
cpstripped (charstring_t dest, size_t max, char *str)
{
static void
cpstripped (charstring_t dest, size_t max, char *str)
{
- int prevCtrl = 1; /* This is 1 so we strip out leading spaces */
- int len;
- }
-
- len = strlen(str);
-
- /*
- * Process each character at a time; if we have multibyte support
- * then deal with that here.
- */
-
- while (*str != '\0' && len > 0 && max > 0) {
- int c = (unsigned char) *str;
- len--;
- if (iscntrl(c) || isspace(c)) {
- str++;
- if (! prevCtrl) {
- charstring_push_back (dest, ' ');
- --max;
- }
-
- prevCtrl = 1;
- continue;
- }
-
- prevCtrl = 0;
- charstring_push_back (dest, *str++);
- --max;
+ squash = true; /* Strip leading cases. */
+ while (max--) {
+ c = (unsigned char)*str++;
+ if (!c)
+ return;
+
+ if (isspace(c) || iscntrl(c)) {
+ if (squash)
+ continue;
+ c = ' ';
+ squash = true;
+ } else
+ squash = false;
+
+ charstring_push_back(dest, (char)c);