strips unwanted string(s), or whitespace by default, from a target string
9770
function stripX(str, unwanted) {
        if (["string"].indexOf(type(str)) < 0)
            throw `stripX(): Invalid str argument type; expected 'string'; found ${type(str)}`;

        if (["undefined", "null", "array", "string"].indexOf(type(unwanted)) < 0)
            throw `stripX(): Invalid unwanted argument type; expected 'string','array','null,'undefined'; found ${type(unwanted)}`;

        switch (type(unwanted)) {
            case "undefined":
            case "null":
                return str.stripWhitespace();

            case "array":
                return unwanted
                    .reduce(function (_cumulative, _current, _index, _arr) {
                        var pos = _cumulative.indexOf(_current);
                        return (pos >= 0)
                            ? _cumulative.substring(0, pos) +
                            _cumulative.substring(pos + s.length, _cumulative.length).stripX(_current)
                            : _cumulative;
                    }, str);

            case "string":
                var pos = str.indexOf(unwanted);
                return (pos >= 0)
                    ? str.substring(0, pos) + str.substring(pos + unwanted.length, str.length).stripX(unwanted)
                    : str;

            default:
                throw `stripX(): Invalid unwanted argument type; expected 'string','array','null,'undefined'; found ${type(unwanted)}`;
        }
    }
405543
private static String cleanString(String s) {
		if (s != null) {
			s = s.trim();
			if (s.equals("")) {
				s = null;
			}
		}
		return s;
	}
374394
def _remove_whitespace(text):
        """"""
        # while True:
        #     old_text = text
        #     text = text.replace('  ', ' ')
        #     if text == old_text:
        #         return text
        non_spaces = re.finditer(r'[^ ]', text)

        if not non_spaces:
            return text

        first_non_space = non_spaces.next()
        first_non_space = first_non_space.start()

        last_non_space = None
        for item in non_spaces:
            last_non_space = item

        if not last_non_space:
            return text[first_non_space:]
        else:
            last_non_space = last_non_space.end()
            return text[first_non_space:last_non_space]
1364933
def stripnull(string):
    """"""
    i = string.find(b'\x00')
    return string if (i < 0) else string[:i]
935471
def normalize_whitespace(self, value):
        """"""
        if isinstance(value, unicode):
            return u" ".join(
                x for x in re.split(r'\s+', value, flags=re.UNICODE) if
                len(x)
            )
        else:
            return " ".join(value.split())
1224535
def cleanup_strings(strings, strip: true)
      strings = Array(strings).flatten.map! { |s| cleanup_string(s, strip: strip) }
      strings.reject!(&:blank?)
      strings
    end
1282685
private void cleanContentLeadingSpaces()
    {
        if (getContent().length() > 0) {
            if (fPreviousInlineText.length() == 0
                || fPreviousInlineText
                .charAt(fPreviousInlineText.length() - 1) == ' ')
            {
                trimLeadingWhiteSpaces();
            }
        }
    }
213106
def clean(inputline, strip=True, rem_indents=True, encoding_errors="replace"):
    """"""
    stdout_encoding = get_encoding(sys.stdout)
    inputline = str(inputline)
    if rem_indents:
        inputline = inputline.replace(openindent, "").replace(closeindent, "")
    if strip:
        inputline = inputline.strip()
    return inputline.encode(stdout_encoding, encoding_errors).decode(stdout_encoding)
821706
def _whitespace_tokenize(self, text):
        """"""
        text = text.strip()
        tokens = text.split()
        return tokens
849809
private String cleanAndTrimString(String text, int maxTextLength) {
        if (StringUtils.isNotBlank(text)) {
            String cleaned = text.trim().replaceAll("[\\s]+", " ");
            return cleaned.length() <= maxTextLength
                    ? cleaned
                    : cleaned.substring(0, maxTextLength) + " ...";
        }
        return text;
    }
1019185
private static String trimTrailingWhitespace(String string) {
        int end = 0;
        char c;

        for (int i = string.length() - 1; i >= 0; i--) {
            c = string.charAt(i);
            if (!Character.isWhitespace(c)) {
                end = i;
                break;
            }
        }

        if (end == 0) {
            return string;
        }

        return string.substring(0, end + 1);
    }
1338849
def skip_whitespace(self, newlines=0):
        
        if newlines:
            while not self.eos:
                if self.get_char().isspace():
                    self.eat_length(1)
                else:
                    break
        else:
            char = ''
            while not self.eos:
                char = self.get_char()
                if char.isspace() and char != '\n':
                    self.eat_length(1)
                else:
                    break
683809
def strip_linebreaks(s):
    
    return u"\n".join([c for c in s.split(u'\n') if c])
299547
def _strip_invisible(s):
    ""
    if isinstance(s, _text_type):
        return re.sub(_invisible_codes, "", s)
    else:  # a bytestring
        return re.sub(_invisible_codes_bytes, "", s)
849452
def _no_trailing_whitespace(relative_path, contents, linter_options):
    """
    del relative_path
    del linter_options

    trailing_whitespace = re.compile(r"(?<![ \t\r\n])[ \t]+$")

    for index, line in enumerate(contents):
        for space in trailing_whitespace.finditer(line):
            assert space.end() == len(line) - 1
            return LinterFailure("Trailing whitespace",
                                 index + 1,
                                 line[:space.start()] + line[space.end():])
400195
def strip_spaces(value, sep=None, join=True):
    """"""
    value = value.strip()
    value = [v.strip() for v in value.split(sep)]
    join_sep = sep or ' '
    return join_sep.join(value) if join else value
1336307
def clean_string(text):
    
    if isinstance(text, six.string_types):
        return text.translate(UNI_SPECIAL_CHARS).strip()
    return text.translate(None, STR_SPECIAL_CHARS).strip()