Skip to content

Commit

Permalink
Merge pull request #1807 from rdkcentral/development/accept-pascalcas…
Browse files Browse the repository at this point in the history
…e-methodname

[Core] Accept pascal-cased method names on JSON-RPC calls
  • Loading branch information
pwielders authored Dec 12, 2024
2 parents 5ede424 + 4832c1b commit 51eff3f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions Source/core/JSONRPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,21 @@ namespace Core {
size_t end = designator.find_last_of('@');
size_t begin = designator.find_last_of('.', end);
size_t lookup = designator.find_first_of('#', begin+1);
string method;

if (lookup != string::npos) {
size_t ns = designator.find_first_of(':', lookup + 1);
return (designator.substr((begin == string::npos) ? 0 : begin + 1, lookup - begin - 1) + (ns != string::npos? designator.substr(ns, end - ns) : string{}));
method = designator.substr((begin == string::npos) ? 0 : begin + 1, lookup - begin - 1) + (ns != string::npos? designator.substr(ns, end - ns) : string{});
}
else {
return (designator.substr((begin == string::npos) ? 0 : begin + 1, (end == string::npos ? string::npos : (begin == string::npos) ? end : end - begin - 1)));
method = designator.substr((begin == string::npos) ? 0 : begin + 1, (end == string::npos ? string::npos : (begin == string::npos) ? end : end - begin - 1));
}

PUSH_WARNING(DISABLE_WARNING_DEPRECATED_USE) // Support pascal casing during the transition period
ToCamelCase(method);
POP_WARNING()

return (method);
}
static string FullMethod(const string& designator)
{
Expand Down Expand Up @@ -420,6 +427,30 @@ namespace Core {
Core::JSON::String Result;
Info Error;

private:
DEPRECATED static void ToCamelCase(string& source)
{
// speed optimized, does not care for locale settings

char* raw = &source[0];

auto const isup = [](const char ch) {
return (static_cast<uint8_t>(ch - 'A') <= 25);
};

auto const islow = [](const char ch) {
return (static_cast<uint8_t>(ch - 'a') <= 25);
};

if (isup(raw[0])) {
*raw++ |= 32;

while (isup(raw[0]) && !islow(raw[1])) {
*raw++ |= 32;
}
}
}

private:
string _implicitCallsign;
};
Expand Down

0 comments on commit 51eff3f

Please sign in to comment.