code: public static String trim(String buffer) {
          // remove spaces in front
          int count = 0;
          for (int i = 0; i < buffer.length(); i++) {
              if (buffer.charAt(i) == SPACE_CHAR)
                  count++;
              else
                  break;
          }
          if (count > 0)
              buffer = buffer.substring(count);
  
          // remove spaces in the end
          count = buffer.length();
          for (int i = buffer.length() - 1; i > 0; i--) {
              if (buffer.charAt(i) == SPACE_CHAR && buffer.charAt(i - 1) != BACK_SLASH)
                  count--;
              else
                  break;
          }
          if (count != buffer.length())
              buffer = buffer.substring(0, count);
  
          return buffer;
      }
docs: Similar to String.trim(), but do not remove spaces that are escaped
  
  @param buffer input
  @return trimmed buffer