Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions villagesql/schema/descriptor/type_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void TypeParameters::build_entries() {
}
}

TypeParameters TypeParameters::from_raw(const std::string &raw) {
TypeParameters TypeParameters::from_raw(const std::string_view raw) {
if (raw.empty()) return TypeParameters();

// Parse "k=v,k=v,..." into pairs, sort by lowercased key, lowercase values,
Expand All @@ -274,29 +274,30 @@ TypeParameters TypeParameters::from_raw(const std::string &raw) {
size_t start = 0;
while (start < raw.size()) {
size_t comma = raw.find(',', start);
if (comma == std::string::npos) comma = raw.size();
if (comma == std::string_view::npos) comma = raw.size();
size_t eq = raw.find('=', start);
if (eq == std::string::npos || eq >= comma) {
if (eq == std::string_view::npos || eq >= comma) {
start = comma + 1;
continue;
}
std::string key = raw.substr(start, eq - start);
std::string value = raw.substr(eq + 1, comma - eq - 1);
std::string_view key = raw.substr(start, eq - start);
std::string_view value = raw.substr(eq + 1, comma - eq - 1);

// Trim whitespace
auto trim = [](std::string &s) {
auto trim = [](std::string_view &s) {
size_t b = s.find_first_not_of(' ');
size_t e = s.find_last_not_of(' ');
s = (b == std::string::npos) ? "" : s.substr(b, e - b + 1);
};
trim(key);
trim(value);

std::string key_str{key};
std::string value_str{value};
// Lowercase
key = casedn(cs, std::move(key));
value = casedn(cs, std::move(value));
key_str = casedn(cs, std::move(key_str));
value_str = casedn(cs, std::move(value_str));

pairs.emplace_back(std::move(key), std::move(value));
pairs.emplace_back(std::move(key_str), std::move(value_str));
start = comma + 1;
}

Expand Down
3 changes: 2 additions & 1 deletion villagesql/schema/descriptor/type_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cctype>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "villagesql/schema/descriptor/type_descriptor.h"
Expand Down Expand Up @@ -89,7 +90,7 @@ class TypeParameters {
// Normalize a raw "k=v,k=v,..." string: split pairs, sort by lowercased
// key, lowercase values, re-serialize. Used by TYPE('k=v,...') SQL parser
// path.
static TypeParameters from_raw(const std::string &raw);
static TypeParameters from_raw(const std::string_view raw);

bool empty() const { return str_.empty(); }
const std::string &str() const { return str_; }
Expand Down
Loading