Java String Sanitize sanitize(String string)

Here you can find the source of sanitize(String string)

Description

sanitize

License

Open Source License

Declaration

static String sanitize(String string) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static String sanitize(String string) {
        string = string.replace(" ", "");
        string = string.replace(")(", ")*(");
        StringBuilder result = new StringBuilder("");
        int depth = 0;
        for (int i = 0; i < string.length(); i++) {
            if (string.charAt(i) == '-' && depth == 0) {
                result.append("+(-1)*");
            } else {
                result.append(string.charAt(i));
            }/*from w w w.  ja v  a  2s .  c  o  m*/
            if (string.charAt(i) == '(') {
                depth++;
            } else if (string.charAt(i) == ')') {
                depth--;
            }
        }
        return result.toString();
    }
}

Related

  1. sanitize(String s)
  2. sanitize(String s)
  3. sanitize(String s, boolean allowColorCodes)
  4. sanitize(String source)
  5. sanitize(String str)
  6. sanitize(String string, boolean allowWhitespace)
  7. sanitize(String string, String spaceReplace)
  8. sanitize(String text)
  9. sanitize(String text)