Skip to content

Commit

Permalink
Replace the regex with isdigit.
Browse files Browse the repository at this point in the history
Signed-off-by: Ye Cao <[email protected]>
  • Loading branch information
dashanji committed Nov 17, 2024
1 parent 6135ff0 commit 833e6a6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/server/server/vineyard_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,18 @@ namespace vineyard {
} while (0)
#endif // ENSURE_VINEYARDD_READY

bool is_all_digits(const std::string& name) {
for (char ch : name) {
if (!std::isdigit(static_cast<unsigned char>(ch))) {
return false;
}
}
return true;
}

// Helper function to adjust the name if it's all digits.
std::string AdjustName(const std::string& name) {
if (std::regex_match(name, std::regex("[0-9]+$"))) {
if (is_all_digits(name)) {
return "_" + name;
}
return name;
Expand Down Expand Up @@ -883,7 +892,7 @@ Status VineyardServer::PutName(const ObjectID object_id,
// as the nlohmann/json can't convert '/names/1234: 12345' to 'names:{"1234",
// "12345"}'
std::string new_name = AdjustName(name);
std::cout << "new_name is: " << new_name << std::endl;

meta_service_ptr_->RequestToPersist(
[object_id, name = new_name](const Status& status, const json& meta,
std::vector<meta_tree::op_t>& ops) {
Expand Down

0 comments on commit 833e6a6

Please sign in to comment.