示例#1
0
文件: CharSeq.java 项目: purgna/fig
 /**
  * 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
文件: CharSeq.java 项目: purgna/fig
  /**
   * 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
文件: CharSeq.java 项目: purgna/fig
 /**
  * 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
文件: CharSeq.java 项目: purgna/fig
 /**
  * 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
文件: CharSeq.java 项目: purgna/fig
 /**
  * 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
文件: CharSeq.java 项目: purgna/fig
 /**
  * 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);
 }