Пример #1
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));
   }
 }
Пример #2
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));
  }
Пример #3
0
 /**
  * Encodes this {@code CharSeq} into a sequence of bytes using the platform's default charset,
  * storing the result into a new Byte Seq.
  *
  * @return A Seq of Byte
  */
 public Seq<Byte> eachByte() {
   byte[] rawBytes = str.getBytes();
   Byte[] bytes = new Byte[rawBytes.length];
   for (int i = 0; i < bytes.length; i++) {
     bytes[i] = rawBytes[i];
   }
   return Seq.of(bytes);
 }
Пример #4
0
 /**
  * Converts this CharSeq to a new Character Seq.
  *
  * @return A Seq of Character
  */
 public Seq<Character> eachChar() {
   char[] chars = str.toCharArray();
   Character[] characters = new Character[str.length()];
   for (int i = 0; i < characters.length; i++) {
     characters[i] = chars[i];
   }
   return Seq.of(characters);
 }
Пример #5
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;
 }
Пример #6
0
 /**
  * Splits this CharSeq around matches of the given regular expression.
  *
  * @param regex Regular expression
  * @return
  */
 public Seq<CharSeq> split(String regex) {
   return Seq.of(str.split(regex)).map(CharSeq::new);
 }