public static StringList splitChars(String _string, params char[] _separators) { StringList l_ = new StringList(); MyList <char> cs_ = new MyList <char>(); foreach (char c in _separators) { cs_.Add(c); } int len_ = _string.Length; StringBuilder str_ = new StringBuilder(); for (int i = FIRST_INDEX; i < len_; i++) { if (cs_.containsObj(_string.ElementAt(i))) { l_.Add(str_.ToString()); str_ = new StringBuilder(); } else { str_.Append(_string.ElementAt(i)); } } l_.Add(str_.ToString()); return(l_); }
public static StringList getTokensSeparators(String _string, String _regExpToken) { int index_ = FIRST_INDEX; Regex patt_ = new Regex(_regExpToken); StringList list_ = new StringList(); while (index_ < _string.Count()) { String sub_ = _string.Substring(index_); Match m_ = patt_.Match(sub_); if (m_.Success) { String token_ = m_.Value; int next_ = sub_.IndexOf(token_); list_.Add(sub_.Substring(FIRST_INDEX, next_)); list_.Add(token_); index_ += next_ + token_.Count(); } else { list_.Add(sub_); break; } } return(list_); }
private static Pair <Pair <StringList, StringList>, Pair <Boolean, Boolean> > wordsAndSeparators(String _string) { Pair <Pair <StringList, StringList>, Pair <Boolean, Boolean> > wordsSepBeginEnd_; wordsSepBeginEnd_ = new Pair <Pair <StringList, StringList>, Pair <Boolean, Boolean> >(); wordsSepBeginEnd_.setSecond(new Pair <Boolean, Boolean>(false, false)); Pair <StringList, StringList> wordsAndSeparators_ = new Pair <StringList, StringList>(); StringList words_ = new StringList(); StringList separators_ = new StringList(); MyList <char> metas_ = getMetaCharacters(); int begin_ = FIRST_INDEX; while (true) { int minIndex_ = lowestIndexOfMetaChar(_string, begin_, metas_); //Console.WriteLine(minIndex_+"%%%%"); if (minIndex_ == INDEX_NOT_FOUND_ELT) { if (begin_ < _string.Count()) { words_.Add(_string.Substring(begin_)); } if (begin_ == FIRST_INDEX) { wordsSepBeginEnd_.getSecond().setFirst(true); } wordsSepBeginEnd_.getSecond().setSecond(begin_ < _string.Count()); break; } if (minIndex_ > begin_) { words_.Add(_string.Substring(begin_, minIndex_ - begin_)); if (begin_ == FIRST_INDEX) { wordsSepBeginEnd_.getSecond().setFirst(true); } } int ind_ = lowestIndexOfWordChar(_string, minIndex_, metas_); //ind_ < _string.length() ==> all character after or at minIndex_ are meta characters //so if ind_ is lower than the length of the string _string, //then this string does not end with a character of word if (ind_ > minIndex_) { separators_.Add(_string.Substring(minIndex_, ind_ - minIndex_)); } begin_ = ind_; } wordsAndSeparators_.setFirst(separators_); wordsAndSeparators_.setSecond(words_); int nbWords_ = wordsAndSeparators_.getSecond().size(); for (int i = FIRST_INDEX; i < nbWords_; i++) { String escapedString_ = escape(wordsAndSeparators_.getSecond().get(i)); wordsAndSeparators_.getSecond().set(i, escapedString_); } wordsSepBeginEnd_.setFirst(wordsAndSeparators_); return(wordsSepBeginEnd_); }
public static StringList splitStrings(String _string, params String[] _separators) { StringList l_ = new StringList(); int len_ = _string.Length; String sub_ = _string; while (true) { String candidate_ = null; int minIndex_ = len_; int maxLength_ = 0; foreach (String s in _separators) { int locIndex_ = sub_.IndexOf(s); if (locIndex_ < 0) { continue; } if (locIndex_ > minIndex_) { continue; } int locLength_ = s.Length; if (locIndex_ < minIndex_) { minIndex_ = locIndex_; maxLength_ = locLength_; candidate_ = s; continue; } if (locLength_ > maxLength_) { maxLength_ = locLength_; candidate_ = s; } } if (candidate_ == null) { l_.Add(sub_); break; } l_.Add(sub_.Substring(FIRST_INDEX, minIndex_)); sub_ = sub_.Substring(minIndex_ + maxLength_); } return(l_); }
static String escapedMeta() { String escaped_ = StringList.BACK_SLASH; StringList list_ = new StringList(); list_.Add(POSSIBLE); list_.Add(AT_LEAST); list_.Add(LEFT_CLASS_REG_EXP); list_.Add(RIGHT_CLASS_REG_EXP); list_.Add(char.ToString(LEFT_BRACE)); list_.Add(char.ToString(RIGHT_BRACE)); list_.Add(char.ToString(LEFT_PAR)); list_.Add(char.ToString(RIGHT_PAR)); list_.Add(POINT); list_.Add(PIPE); escaped_ += list_.join(PIPE + StringList.BACK_SLASH); return(pars(escaped_)); }
public static String outOfClassOfCharacters(params String[] _args) { StringList escaped_ = new StringList(); foreach (String s in _args) { escaped_.Add(quote(s)); } return(LEFT_CLASS_REG_EXP + BEGIN_REG_EXP + escaped_.join(EMPTY_STRING) + RIGHT_CLASS_REG_EXP); }
public static StringList getTypes(String _type) { StringList types_ = new StringList(); int i_ = _type.IndexOf(char.ToString('[')); if (i_ == INDEX_NOT_FOUND_ELT) { return(types_); } i_++; int nbGt_ = 0; int nbLt_ = 0; int first_ = i_; while (true) { if (i_ >= _type.Count() - 1) { types_.Add(_type.Substring(first_, i_ - first_)); break; } if (_type.ElementAt(i_) == COMMA) { if (nbGt_ == nbLt_) { types_.Add(_type.Substring(first_, i_ - first_)); first_ = i_ + 1; } } if (_type.ElementAt(i_) == '[') { nbGt_++; } if (_type.ElementAt(i_) == ']') { nbLt_++; } i_++; } return(types_); }
public static StringList matchingRegExp(String _string, String _regExp) { Match m_ = new Regex(_regExp).Match(_string); StringList list_ = new StringList(); while (m_.Success) { list_.Add(m_.Value); m_ = m_.NextMatch(); } return(list_); }
public StringList filterByMultiWords(String _exp) { StringList list_ = new StringList(); foreach (String s in this) { if (!match(s, _exp)) { continue; } list_.Add(s); } return(list_); }
public StringList filterIgnoreCase(String _regExp) { StringList list_ = new StringList(); Regex patt_ = new Regex(_regExp.ToUpper()); foreach (String s in this) { if (!patt_.Match(s.ToUpper()).Success) { continue; } list_.Add(s); } return(list_); }
public StringList stringsEqualsIgnoreCase(String _string) { StringList list_ = new StringList(); foreach (String s in this) { if (s == null) { continue; } if (string.Equals(s, _string, StringComparison.OrdinalIgnoreCase)) { list_.Add(s); } } return(list_); }
public static void setupDocument(XmlDocument _xml) { XmlElement mainElt_ = XmlParser.documentElement(_xml); MyList <XmlNode> currentNodes_ = new MyList <XmlNode>(); currentNodes_.Add(mainElt_); MyList <XmlNode> newNodes_ = new MyList <XmlNode>(); while (true) { foreach (XmlNode n in currentNodes_) { bool final_ = true; //bool noChild_ = true; foreach (XmlNode e in XmlParser.childrenNodes(n)) { bool empty_ = true; //noChild_ = false; foreach (XmlNode x in XmlParser.childrenNodes(e)) { if (!(x as XmlElement).GetAttribute(TYPE_INT).isEmpty()) { empty_ = false; break; } } if (!empty_) { final_ = false; newNodes_.Add(e); } /*else if (!(e as XmlElement).GetAttribute(TYPE_INT).isEmpty()) * { * newNodes_.Add(e); * }*/ } if (final_) {// && !noChild_ StringList types_ = new StringList(); foreach (XmlNode e in XmlParser.childrenNodes(n)) { XmlElement e_ = e as XmlElement; types_.Add("[" + e_.GetAttribute(TYPE_INT) + ", " + e_.GetAttribute(ASSEMBLY_INT) + "]"); e_.SetAttribute(TYPE_INT, ""); } XmlElement n_ = n as XmlElement; if (!types_.isEmpty()) { string typeLoc_ = n_.GetAttribute(TYPE_INT); typeLoc_ += "[" + types_.join(", ") + "]"; n_.SetAttribute(TYPE_INT, typeLoc_); } } } if (newNodes_.isEmpty()) { break; } currentNodes_ = new MyList <XmlNode>(newNodes_); newNodes_ = new MyList <XmlNode>(); } }
public static bool match(String _string, String _filter) { if (_filter.isEmpty()) { return(true); } Pair <Pair <StringList, StringList>, Pair <Boolean, Boolean> > wordsAndSeparators_ = wordsAndSeparators(_filter); Console.WriteLine(wordsAndSeparators_); StringList words_ = wordsAndSeparators_.getFirst().getSecond(); StringList separators_ = wordsAndSeparators_.getFirst().getFirst(); String lastSep_; int nbPts_ = SIZE_EMPTY; int nbZeroOne_ = SIZE_EMPTY; int index_ = FIRST_INDEX; if (words_.isEmpty()) { lastSep_ = separators_.last(); nbPts_ = 0; nbZeroOne_ = 0; index_ = FIRST_INDEX; foreach (char c in lastSep_.ToCharArray()) { if (c == CHARACTER) { nbPts_++; } if (c == POSSIBLE_CHAR) { nbZeroOne_++; } } index_ += nbPts_; if (index_ == _string.Count()) { return(true); } if (index_ < _string.Count()) { if (lastSep_.Contains(char.ToString(STRING))) { return(true); } if (_string.Count() <= index_ + nbZeroOne_) { return(true); } } return(false); } if (wordsAndSeparators_.getSecond().getFirst()) { separators_.Insert(FIRST_INDEX, EMPTY_STRING); } //BEGIN MODIF /*if (separators_.isEmpty()) * { * if (wordsAndSeparators_.getSecond().getSecond()) * { * separators_.Add(EMPTY_STRING); * } * }*/ //END MODIF if (wordsAndSeparators_.getSecond().getSecond()) { separators_.Add(EMPTY_STRING); } int i_ = FIRST_INDEX; index_ = FIRST_INDEX; int indiceRDecalePt_ = 0; int indiceNext_ = 0; foreach (String e in words_) { String sep_ = separators_.get(i_); nbPts_ = 0; nbZeroOne_ = 0; foreach (char c in sep_.ToCharArray()) { if (c == CHARACTER) { nbPts_++; } if (c == POSSIBLE_CHAR) { nbZeroOne_++; } } indiceRDecalePt_ = index_ + nbPts_; //indiceNext_ = _string.IndexOf(e, indiceRDecalePt_); if (separators_.get(i_).Contains(char.ToString(STRING))) { if (words_.isValidIndex(i_ + 1)) { indiceNext_ = _string.IndexOf(e, indiceRDecalePt_); //indiceNext_ = greatestIndex(_string, e, indiceRDecalePt_); if (indiceNext_ == INDEX_NOT_FOUND_ELT) { return(false); } } else { indiceNext_ = greatestIndex(_string, e, indiceRDecalePt_); if (indiceNext_ == INDEX_NOT_FOUND_ELT) { return(false); } } } else { indiceNext_ = _string.IndexOf(e, indiceRDecalePt_); if (indiceRDecalePt_ > indiceNext_ || indiceRDecalePt_ < indiceNext_ - nbZeroOne_) { return(false); } } index_ = indiceNext_ + e.Count(); i_++; } Console.WriteLine(separators_); lastSep_ = separators_.last(); Console.WriteLine(lastSep_ + "%" + _string + "%" + _filter); nbPts_ = 0; nbZeroOne_ = 0; foreach (char c in lastSep_.ToCharArray()) { if (c == CHARACTER) { nbPts_++; } if (c == POSSIBLE_CHAR) { nbZeroOne_++; } } index_ += nbPts_; if (index_ == _string.Count()) { return(true); } if (index_ < _string.Count()) { if (lastSep_.Contains(char.ToString(STRING))) { return(true); } if (_string.Count() <= index_ + nbZeroOne_) { return(true); } } return(false); }
public static String format(String _pattern, char _sep, Map <String, String> _map) { int length_ = _pattern.Length; StringBuilder strBuilder_ = new StringBuilder(); int i_ = List.FIRST_INDEX; StringList keys_ = new StringList(_map.getKeys()); bool quoted_ = false; while (i_ < length_) { if (quoted_) { if (_pattern.ElementAt(i_) != _sep) { strBuilder_.Append(_pattern.ElementAt(i_)); i_++; continue; } quoted_ = false; i_++; continue; } int nbSeqQuotes_ = SIZE_EMPTY; while (true) { if (i_ >= length_) { break; } if (_pattern.ElementAt(i_) != _sep) { break; } nbSeqQuotes_++; i_++; } quoted_ = nbSeqQuotes_ % 2 == 1; int nbAdds_ = nbSeqQuotes_ / 2; for (int i = SIZE_EMPTY; i < nbAdds_; i++) { strBuilder_.Append(_sep); } if (quoted_) { continue; } int j_ = List.FIRST_INDEX; StringList list_ = keys_; while (true) { StringList nexList_ = new StringList(); foreach (String k in list_) { if (k.Length <= j_) { continue; } if (k.ElementAt(j_) == _pattern.ElementAt(j_ + i_)) { nexList_.Add(k); } } list_ = nexList_; String subString_ = _pattern.Substring(i_, j_ + 1); if (list_.containsObj(subString_)) { strBuilder_.Append(_map.getVal(subString_)); i_ += j_; break; } if (list_.isEmpty()) { strBuilder_.Append(subString_); i_ += j_; break; } j_++; } i_++; } return(strBuilder_.ToString()); }
public static String formatBasic(String _pattern, Map <String, String> _map, bool _substringFirst) { bool exit_; int i_; int length_; StringBuilder strBuilder_; StringList keys_; String subString_; if (_substringFirst) { length_ = _pattern.Length; strBuilder_ = new StringBuilder(); i_ = List.FIRST_INDEX; keys_ = new StringList(_map.getKeys()); exit_ = false; while (i_ < length_) { int j_ = List.FIRST_INDEX; StringList list_ = keys_; while (true) { StringList nexList_ = new StringList(); foreach (String k in list_) { if (k.Length <= j_) { continue; } if (k.ElementAt(j_) == _pattern.ElementAt(j_ + i_)) { nexList_.Add(k); } } list_ = nexList_; if (_pattern.Length <= j_ + i_ + 1) { exit_ = true; subString_ = _pattern.Substring(i_); if (list_.containsObj(subString_)) { strBuilder_.Append(_map.getVal(subString_)); } else { strBuilder_.Append(subString_); } break; } subString_ = _pattern.Substring(i_, j_ + 1); if (list_.containsObj(subString_)) { strBuilder_.Append(_map.getVal(subString_)); i_ += j_; break; } if (list_.isEmpty()) { strBuilder_.Append(subString_); i_ += j_; break; } j_++; } if (exit_) { break; } i_++; } return(strBuilder_.ToString()); } length_ = _pattern.Length; strBuilder_ = new StringBuilder(); i_ = List.FIRST_INDEX; keys_ = new StringList(_map.getKeys()); exit_ = false; while (i_ < length_) { int j_ = List.FIRST_INDEX; StringList list_ = keys_; while (true) { StringList nexList_ = new StringList(); foreach (String k in list_) { if (k.Length <= j_) { continue; } if (k.ElementAt(j_) == _pattern.ElementAt(j_ + i_)) { nexList_.Add(k); } } list_ = nexList_; if (_pattern.Length <= j_ + i_ + 1) { exit_ = true; subString_ = _pattern.Substring(i_); if (list_.containsObj(subString_)) { strBuilder_.Append(_map.getVal(subString_)); } else { strBuilder_.Append(subString_); } break; } subString_ = _pattern.Substring(i_, j_ + 1); StringList filterList_ = new StringList(list_); bool exist_ = false; foreach (String s in filterList_) { if (s.Contains(subString_ + _pattern.ElementAt(j_ + i_ + 1))) { exist_ = true; break; } } if (list_.containsObj(subString_) && !exist_) { strBuilder_.Append(_map.getVal(subString_)); i_ += j_; break; } if (list_.isEmpty()) { strBuilder_.Append(subString_); i_ += j_; break; } j_++; } if (exit_) { break; } i_++; } return(strBuilder_.ToString()); }