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_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; }
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; }