-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement functions UCASE and LCASE #1060
Changes from 2 commits
c6c2361
98db4c0
d66c70d
720f4b3
5eca6db
6e08e68
e865101
fa48d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,20 @@ std::string getLowercaseUtf8(std::string_view s) { | |
return result; | ||
} | ||
|
||
// Get the uppercase value. For details see `getLowercaseUtf8` above | ||
inline std::string getUppercaseUtf8(std::string_view s) { | ||
std::string result; | ||
icu::StringByteSink<std::string> sink(&result); | ||
UErrorCode err = U_ZERO_ERROR; | ||
icu::CaseMap::utf8ToUpper( | ||
"", 0, icu::StringPiece{s.data(), static_cast<int32_t>(s.size())}, sink, | ||
nullptr, err); | ||
if (U_FAILURE(err)) { | ||
throw std::runtime_error(u_errorName(err)); | ||
} | ||
return result; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the almost identical code, how about a helper function Also, it looks like it would be more consistent to name the two functions based on this helper function |
||
/** | ||
* @brief get a prefix of a utf-8 string of a specified length | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cascaded question: When exactly is the argument
std.:nullopt
, when the argument given in the SPARQL query was not actually a string? If yes, is the result of a built-in SPARQL function taking one or several string as argument always UNDEF when one of these arguments is not a string? If yes, should this be handled in the functions or outside? I am asking because for the numeric functions thereturn Id::makeUndefined
happens elsewhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a good idea.
For the Numeric functions we have a wrapper that handles the "invalid input" -> expression error -> UNDEF result case automagically,
But we could extend this to all kinds of expressions, s.t. for example the string function implementations only need to handle a
string
instead of anstd::optional<std::string>
.I will think of something and integrate it into one of the next PRs.