WIP : preprocessing to remove all the unused whitespace
339465
protected function ws_trim(){
    if ( $this->ws_keep() ) return;
    
    switch(self::$_ws_state) {
      case self::WS_SPACE: 
        $node = $this->_node;
        
        if ( $node->nodeName === "#text" ) {
          $node->data = preg_replace("/[ \t\r\n\f]+/u", " ", $text);
          
          // starts with a whitespace
          if ( isset($node->data[0]) && $node->data[0] === " " ) {
            $node->data = ltrim($node->data);
          }
          
          // if not empty
          if ( $node->data !== "" ) {
            // change the current state (text)
            self::$_ws_state = self::WS_TEXT;
          
            // ends with a whitespace
            if ( preg_match("/[ \t\r\n\f]+$/u", $node->data) ) {
              $node->data = ltrim($node->data);
            }
          }
        }
      break;
      
      case self::WS_TEXT:
    }
  }
1103643
public void trim() {
    	try
    	{
    	//cut white spaces from the head
		while (len>0 && chars[pos] == ' ') {
			pos++;
			len--;
		}
    	
        //cut from the end
        while (len>0 && (chars[pos + len - 1] == ' ' || chars[pos + len - 1] == '\n' || chars[pos + len - 1] == '\r')) {
            len--;
        }
    	}
    	catch(Exception e)
    	{
    		System.out.println("len:" + len + ",pos:" + pos);
    	}
    }
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]
917207
function getPropertyWhitespace(property) {
            const whitespace = /(\s*):(\s*)/u.exec(sourceCode.getText().slice(
                property.key.range[1], property.value.range[0]
            ));

            if (whitespace) {
                return {
                    beforeColon: whitespace[1],
                    afterColon: whitespace[2]
                };
            }
            return null;
        }
796430
def fix_whitespace(tokens, start, result):
    """"""
    for e in result:
        for child in e.iter():
            child.text = child.text.replace(' , ', ', ')
            for hyphen in HYPHENS:
                child.text = child.text.replace(' %s ' % hyphen, '%s' % hyphen)
            child.text = re.sub(r'- (.) -', r'-\1-', child.text)
    return result
2192
function minify(src) {
       // remove comments
       src = src.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "$1"); // Remove leading and trailing whitespace from lines

       src = src.replace(/(\\n\s+)|(\s+\\n)/g, ""); // Remove line breaks

       src = src.replace(/(\\r|\\n)+/g, ""); // Remove unnecessary whitespace

       src = src.replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g, "$1");
       return src;
     }
695415
function strip_whitespace (s) {
      if (options.strip_whitespace) {
        return s.replace(/\s*\n/g,"\n").replace(/(\r?\n){2,}/g,"\n\n");
      }
      return s;
    }
77528
private static String trimLeadingWhitespace(String string) {
        if (string.isEmpty()) {
            return string;
        }

        int start = 0;
        char c;

        for (int i = 0; i < string.length(); i++) {
            c = string.charAt(i);
            if (!Character.isWhitespace(c)) {
                start = i;
                break;
            }
        }

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

        return string.substring(start);
    }
924835
void trimWhitespaceFromFunctionEnd() {
		assert (callStack.getCurrentElement().type == PushPopType.Function);

		int functionStartPoint = callStack.getCurrentElement().functionStartInOuputStream;

		// If the start point has become -1, it means that some non-whitespace
		// text has been pushed, so it's safe to go as far back as we're able.
		if (functionStartPoint == -1) {
			functionStartPoint = 0;
		}

		// Trim whitespace from END of function call
		for (int i = outputStream.size() - 1; i >= functionStartPoint; i--) {
			RTObject obj = outputStream.get(i);

			if (!(obj instanceof StringValue))
				continue;
			StringValue txt = (StringValue) obj;

			if (obj instanceof ControlCommand)
				break;

			if (txt.isNewline() || txt.isInlineWhitespace()) {
				outputStream.remove(i);
				outputStreamDirty();
			} else {
				break;
			}
		}
	}
731917
private byte[] stripWhiteSpaces(byte[] data) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        for (byte b : data) {
            if (!WHITESPACES.contains(b)) {
                bos.write(b);
            }
        }
        return bos.toByteArray();
    }
264797
function skipWhitespace() {
    while (i < input.length) {
      if (isWhitespace(input[i])) {
        i++;
        parser.pos_++;
        continue;
      }
      break;
    }
  }
798205
def width_cal_preprocess(content):
    
    ptn = re.compile(r'(\033|\x1b)\[.*?m', re.I)
    _content = re.sub(ptn, '', content) # remove ANSI escape code
    return _content
125818
def fix_whitespace(line, offset, replacement):
    """"""
    # Replace escaped newlines too
    left = line[:offset].rstrip('\n\r \t\\')
    right = line[offset:].lstrip('\n\r \t\\')
    if right.startswith('#'):
        return line
    else:
        return left + replacement + right
1016056
def _delete_horizontal_space(text, pos):
    """"""
    while pos > 0 and text[pos - 1].isspace():
        pos -= 1
    end_pos = pos
    while end_pos < len(text) and text[end_pos].isspace():
        end_pos += 1
    return text[:pos] + text[end_pos:], pos
302397
def _snip_whitespace(
            self,
            text):
        
        self.log.debug('starting the ``_snip_whitespace`` method')

        m = self.reWS.match(text)

        prefix = m.group(1)
        text = m.group(2)
        suffix = m.group(3)

        self.log.debug('completed the ``_snip_whitespace`` method')
        return prefix, text, suffix
693084
def remove_whitespace(self, html):
        
        # Does python have a better way to do exactly this?
        clean_html = html
        for char in ("\r", "\n", "\t"):
            clean_html = clean_html.replace(char, "")
        return clean_html
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