pal::string_t trim_quotes(pal::string_t stringToCleanup) { pal::char_t quote_array[2] = {'\"', '\''}; for(int index = 0; index < sizeof(quote_array)/sizeof(quote_array[0]); index++) { size_t pos = stringToCleanup.find(quote_array[index]); while(pos != std::string::npos) { stringToCleanup = stringToCleanup.erase(pos, 1); pos = stringToCleanup.find(quote_array[index]); } } return stringToCleanup; }
pal::string_t get_replaced_char(const pal::string_t& path, pal::char_t match, pal::char_t repl) { int pos = path.find(match); if (pos == pal::string_t::npos) { return path; } pal::string_t out = path; do { out[pos] = repl; } while ((pos = out.find(match, pos)) != pal::string_t::npos); return out; }
// For some distros, we don't want to use the full version from VERSION_ID. One example is // Red Hat Enterprise Linux, which includes a minor version in their VERSION_ID but minor // versions are backwards compatable. // // In this case, we'll normalized RIDs like 'rhel.7.2' and 'rhel.7.3' to a generic // 'rhel.7'. This brings RHEL in line with other distros like CentOS or Debian which // don't put minor version numbers in their VERSION_ID fields because all minor versions // are backwards compatible. static pal::string_t normalize_linux_rid(pal::string_t rid) { pal::string_t rhelPrefix(_X("rhel.")); if (rid.compare(0, rhelPrefix.length(), rhelPrefix) == 0) { size_t minorVersionSeparatorIndex = rid.find(_X("."), rhelPrefix.length()); if (minorVersionSeparatorIndex != std::string::npos) { rid.erase(minorVersionSeparatorIndex, rid.length() - minorVersionSeparatorIndex); } } return rid; }
/** * Given path to app binary, say app.dll or app.exe, retrieve the app.deps.json. */ pal::string_t get_deps_from_app_binary(const pal::string_t& app) { assert(app.find(DIR_SEPARATOR) != pal::string_t::npos); assert(ends_with(app, _X(".dll"), false) || ends_with(app, _X(".exe"), false)); // First append directory. pal::string_t deps_file; deps_file.assign(get_directory(app)); deps_file.push_back(DIR_SEPARATOR); // Then the app name and the file extension pal::string_t app_name = get_filename(app); deps_file.append(app_name, 0, app_name.find_last_of(_X("."))); deps_file.append(_X(".deps.json")); return deps_file; }
bool LongFile::ContainsDirectorySeparator(const pal::string_t & path) { return path.find(DirectorySeparatorChar) != pal::string_t::npos || path.find(AltDirectorySeparatorChar) != pal::string_t::npos; }
bool parse_internal(const pal::string_t& ver, fx_ver_t* fx_ver, bool parse_only_production) { size_t maj_start = 0; size_t maj_sep = ver.find(_X('.')); if (maj_sep == pal::string_t::npos) { return false; } unsigned major = 0; if (!try_stou(ver.substr(maj_start, maj_sep), &major)) { return false; } size_t min_start = maj_sep + 1; size_t min_sep = ver.find(_X('.'), min_start); if (min_sep == pal::string_t::npos) { return false; } unsigned minor = 0; if (!try_stou(ver.substr(min_start, min_sep - min_start), &minor)) { return false; } unsigned patch = 0; size_t pat_start = min_sep + 1; size_t pat_sep = ver.find_first_not_of(_X("0123456789"), pat_start); if (pat_sep == pal::string_t::npos) { if (!try_stou(ver.substr(pat_start), &patch)) { return false; } *fx_ver = fx_ver_t(major, minor, patch); return true; } if (parse_only_production) { // This is a prerelease or has build suffix. return false; } if (!try_stou(ver.substr(pat_start, pat_sep - pat_start), &patch)) { return false; } size_t pre_start = pat_sep; size_t pre_sep = ver.find(_X('+'), pre_start); if (pre_sep == pal::string_t::npos) { *fx_ver = fx_ver_t(major, minor, patch, ver.substr(pre_start)); return true; } else { size_t build_start = pre_sep + 1; *fx_ver = fx_ver_t(major, minor, patch, ver.substr(pre_start, pre_sep - pre_start), ver.substr(build_start)); return true; } }