code: public static String sanitize (String source, CharacterValidator validator)
      {
          if (source == null) {
              return null;
          }
          int nn = source.length();
          StringBuilder buf = new StringBuilder(nn);
          for (int ii=0; ii < nn; ii++) {
              char c = source.charAt(ii);
              if (validator.isValid(c)) {
                  buf.append(c);
              }
          }
          return buf.toString();
      }
docs: Sanitize the specified String so that only valid characters are in it.