xo-tokenizer2/xo-websock/src/websock/EndpointUtil.cpp
Roland Conybeare dd1a6b1afc Add 'xo-websock/' from commit '57bf06a68f'
git-subtree-dir: xo-websock
git-subtree-mainline: 97eefaea22
git-subtree-split: 57bf06a68f
2025-05-11 15:08:51 -05:00

38 lines
1,001 B
C++

/* file EndpointUtil.cpp
*
* author: Roland Conybeare, Sep 2022
*/
#include "EndpointUtil.hpp"
namespace xo {
namespace web {
std::string
EndpointUtil::stem(std::string const & pattern)
{
std::size_t p = 0;
do {
p = pattern.find_first_of("$", p);
if ((p != std::string::npos) && (pattern[p+1] == '{')) {
/* fixed stem is chars [0 .. p-1], i.e. 1st p characters */
break;
}
if (p != std::string::npos) {
/* skip to next '$' */
++p;
}
} while (p != std::string::npos);
if (p == std::string::npos) {
/* pattern has no variable components */
return pattern;
} else {
return pattern.substr(0, p);
}
} /*stem*/
} /*namespace web*/
} /*namespace xo*/
/* end EndpointUtil.cpp */