Lines Matching defs:str

151 void AppendString(StringPiece str, string* out) {
152 out->append(str.begin(), str.end());
155 bool HasPrefix(StringPiece str, StringPiece prefix) {
156 ssize_t size_diff = str.size() - prefix.size();
157 return size_diff >= 0 && str.substr(0, prefix.size()) == prefix;
160 bool HasSuffix(StringPiece str, StringPiece suffix) {
161 ssize_t size_diff = str.size() - suffix.size();
162 return size_diff >= 0 && str.substr(size_diff) == suffix;
165 bool HasWord(StringPiece str, StringPiece w) {
166 size_t found = str.find(w);
169 if (found != 0 && !isSpace(str[found-1]))
172 if (end != str.size() && !isSpace(str[end]))
177 StringPiece TrimPrefix(StringPiece str, StringPiece prefix) {
178 ssize_t size_diff = str.size() - prefix.size();
179 if (size_diff < 0 || str.substr(0, prefix.size()) != prefix)
180 return str;
181 return str.substr(prefix.size());
184 StringPiece TrimSuffix(StringPiece str, StringPiece suffix) {
185 ssize_t size_diff = str.size() - suffix.size();
186 if (size_diff < 0 || str.substr(size_diff) != suffix)
187 return str;
188 return str.substr(0, size_diff);
195 bool Pattern::Match(StringPiece str) const {
197 return str == pat_;
198 return MatchImpl(str);
201 bool Pattern::MatchImpl(StringPiece str) const {
202 return (HasPrefix(str, pat_.substr(0, percent_index_)) &&
203 HasSuffix(str, pat_.substr(percent_index_ + 1)));
206 StringPiece Pattern::Stem(StringPiece str) const {
207 if (!Match(str))
209 return str.substr(percent_index_,
210 str.size() - (pat_.size() - percent_index_ - 1));
213 void Pattern::AppendSubst(StringPiece str, StringPiece subst,
216 if (str == pat_) {
220 AppendString(str, out);
225 if (MatchImpl(str)) {
232 AppendString(str.substr(percent_index_,
233 str.size() - pat_.size() + 1), out);
238 AppendString(str, out);
241 void Pattern::AppendSubstRef(StringPiece str, StringPiece subst,
244 AppendSubst(str, subst, out);
247 StringPiece s = TrimSuffix(str, pat_);
510 string EchoEscape(const string &str) {
511 const char *in = str.c_str();