str js_lang::expression_path(const str& expr ) { size_t pos = expr.find_last_of("."); if (pos != str::npos) { return str(expr.begin(), expr.begin() + pos); } return str(); }
void disp(str v) { for (sit it=v.begin(); it!=v.end(); it++) cout << *it << endl; cout << endl; }
/************************************************* S.count(sub[, start[, end]]) -> uint Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation. *************************************************/ uint str::count(const str& sub, int start, int end) { return ::count((start<0?s.end():s.begin())+start, (end<=0?s.end():s.begin())+end, sub.begin(), sub.end()); }
/************************************************* S.endswith(suffix[, start[, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try. *************************************************/ bool str::endswith(const str& prefix, int start, int end) const { return ::endswith((start<0?s.end():s.begin())+start, (end<=0?s.end():s.begin())+end, prefix.begin(), prefix.end()); }
/************************************************* S.find(sub [,start [,end]]) -> int Search from left to right. Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. *************************************************/ int str::find(const str& sub, int start, int end) const { citerator a=(start<0?s.end():s.begin())+start, b=(end<=0?s.end():s.begin())+end; if (a>=b) return -1; citerator c=std::search(a, b, sub.begin(), sub.end()); return (c==b)?-1:c-a; }