bool w_string_piece::operator<(w_string_piece other) const { int res; if (size() < other.size()) { res = memcmp(data(), other.data(), size()); return (res == 0 ? -1 : res) < 0; } else if (size() > other.size()) { res = memcmp(data(), other.data(), other.size()); return (res == 0 ? +1 : res) < 0; } return memcmp(data(), other.data(), size()) < 0; }
bool w_string_equal_caseless(w_string_piece a, w_string_piece b) { uint32_t i; if (a.size() != b.size()) { return false; } for (i = 0; i < a.size(); i++) { if (tolower((uint8_t)a[i]) != tolower((uint8_t)b[i])) { return false; } } return true; }
// For each directory component in candidate_dir to the root of the filesystem, // look for root_file. If root_file is present, update relpath to reflect the // relative path to the original value of candidate_dir and return true. If // not found, return false. candidate_dir is modified by this function if // return true. static bool find_file_in_dir_tree( const w_string& root_file, w_string_piece& candidate_dir, w_string_piece& relpath) { w_string_piece current_dir(candidate_dir); while (true) { auto projPath = w_string::pathCat({current_dir, root_file}); if (w_path_exists(projPath.c_str())) { // Got a match relpath = w_string_piece(candidate_dir); if (candidate_dir.size() == current_dir.size()) { relpath = w_string_piece(); } else { relpath.advance(current_dir.size() + 1); candidate_dir = current_dir; } return true; } auto parent = current_dir.dirName(); if (parent == nullptr || parent == current_dir) { return false; } current_dir = parent; } return false; }
bool w_string_piece::operator==(w_string_piece other) const { if (s_ == other.s_ && e_ == other.e_) { return true; } if (size() != other.size()) { return false; } return memcmp(data(), other.data(), size()) == 0; }
bool w_string_piece::hasSuffix(w_string_piece suffix) const { unsigned int base, i; if (size() < suffix.size() + 1) { return false; } base = size() - suffix.size(); if (s_[base - 1] != '.') { return false; } for (i = 0; i < suffix.size(); i++) { if (tolower((uint8_t)s_[base + i]) != suffix[i]) { return false; } } return true; }
bool w_string_piece::startsWithCaseInsensitive(w_string_piece prefix) const{ if (prefix.size() > size()) { return false; } auto me = s_; auto pref = prefix.s_; while (pref < prefix.e_) { if (tolower((uint8_t)*me) != tolower((uint8_t)*pref)) { return false; } ++pref; ++me; } return true; }
w_string w_dir_path_cat_str( const struct watchman_dir* dir, w_string_piece extra) { uint32_t length = 0; const struct watchman_dir* d; w_string_t *s; char *buf, *end; if (extra.size()) { length = extra.size() + 1 /* separator */; } for (d = dir; d; d = d->parent) { length += d->name.size() + 1 /* separator OR final NUL terminator */; } s = (w_string_t*)(new char[sizeof(*s) + length]); new (s) watchman_string(); s->refcnt = 1; s->len = length - 1; buf = (char *)(s + 1); end = buf + s->len; *end = 0; if (extra.size()) { end -= extra.size(); memcpy(end, extra.data(), extra.size()); } for (d = dir; d; d = d->parent) { if (d != dir || (extra.size())) { --end; *end = '/'; } end -= d->name.size(); memcpy(end, d->name.data(), d->name.size()); } s->buf = buf; return w_string(s, false); }
void ChildProcess::Options::chdir(w_string_piece path) { cwd_ = std::string(path.data(), path.size()); #ifdef _WIN32 posix_spawnattr_setcwd_np(&inner_->attr, cwd_.c_str()); #endif }
bool w_string_piece::startsWith(w_string_piece prefix) const { if (prefix.size() > size()) { return false; } return memcmp(data(), prefix.data(), prefix.size()) == 0; }