Exemplo n.º 1
0
 /**
  * Scan through this CharSeq iteratively, generate a Seq of CharSeq with all the matching
  * subStrings.
  *
  * @param regex The regular expression
  * @return A Seq of CharSeq
  */
 public Seq<CharSeq> scan(String regex) {
   Pattern pat = Pattern.compile(regex);
   Matcher m = pat.matcher(str);
   Seq<CharSeq> charSeq = Seq.of();
   while (m.find()) {
     charSeq.add(CharSeq.of(m.group()));
   }
   return charSeq;
 }
Exemplo n.º 2
0
 /**
  * Return a new CharSeq with all characters' cases toggled.
  *
  * <p>Examples:
  *
  * <blockquote>
  *
  * <pre>
  * CharSeq.of("sTrEsSed").swapcase() returns CharSeq.of("StReSsED")
  * </pre>
  *
  * </blockquote>
  *
  * @return A new CharSeq
  */
 public CharSeq swapcase() {
   char[] chars = str.toCharArray();
   for (int i = 0; i < chars.length; i++) {
     char c = chars[i];
     if (Character.isUpperCase(c)) {
       chars[i] = Character.toLowerCase(c);
     } else if (Character.isLowerCase(c)) {
       chars[i] = Character.toUpperCase(c);
     } else {
       chars[i] = c;
     }
   }
   return CharSeq.of(chars);
 }
Exemplo n.º 3
0
 /**
  * Searches pattern (regex) in the CharSeq and returns a Seq of CharSeq consists of the part
  * before it, the first match, and the part after it.
  *
  * <p>If no such match is found in this CharSeq, return a Seq of CharSeq consists two empty
  * CharSeqs and the CharSeq itself.
  *
  * @param regex Regular Expression
  * @return A Seq of CharSeq
  */
 public Seq<CharSeq> partition(String regex) {
   Matcher m = Pattern.compile(regex).matcher(str);
   if (m.find()) {
     return Seq.of(
         CharSeq.of(str.substring(0, m.start())),
         CharSeq.of(m.group()),
         CharSeq.of(str.substring(m.end())));
   } else {
     return Seq.of(CharSeq.of(""), CharSeq.of(""), CharSeq.of(str));
   }
 }
Exemplo n.º 4
0
  /**
   * Searches pattern (regex) in the CharSeq and returns a Seq of CharSeq consists of the part
   * before it, the last match, and the part after it.
   *
   * <p>If no such match is found in this CharSeq, return a Seq of CharSeq consists of two empty
   * CharSeqs and the CharSeq itself.
   *
   * @param regex Regular Expression
   * @return A Seq of CharSeq
   */
  public Seq<CharSeq> rPartition(String regex) {
    Matcher m = Pattern.compile(regex).matcher(str);

    String match = null;
    int start = 0, end = 0;
    while (m.find()) {
      match = m.group();
      start = m.start();
      end = m.end();
    }
    if (match != null) {
      return Seq.of(
          CharSeq.of(str.substring(0, start)), CharSeq.of(match), CharSeq.of(str.substring(end)));
    }
    return Seq.of(CharSeq.of(""), CharSeq.of(""), CharSeq.of(str));
  }
Exemplo n.º 5
0
 /**
  * Return a new CharSeq by replacing each substring of this CharSeq that matches the given regular
  * expression with the given String replacement.
  *
  * @param regex The regular expression
  * @param replacement The replacement String
  * @return A new CharSeq
  */
 public CharSeq replaceAll(String regex, String replacement) {
   return CharSeq.of(str.replaceAll(regex, replacement));
 }
Exemplo n.º 6
0
 /**
  * Returns a CharSeq whose value is this CharSeq, with any leading and trailing whitespace
  * removed.
  *
  * @return A new CharSeq with leading and trailing whitespace removed
  */
 public CharSeq trim() {
   return CharSeq.of(str.trim());
 }
Exemplo n.º 7
0
 /**
  * Return a new CharSeq with the characters from this CharSeq in reverse order.
  *
  * <p>Examples:
  *
  * <blockquote>
  *
  * <pre>
  * CharSeq.of("stressed").reverse() returns CharSeq.of("desserts")
  * </pre>
  *
  * </blockquote>
  *
  * @return A new Seq
  */
 public CharSeq reverse() {
   return CharSeq.of(new StringBuilder(str).reverse().toString());
 }