diff options
author | Chang Liu <liuchang0812@gmail.com> | 2017-11-28 13:10:04 +0100 |
---|---|---|
committer | Chang Liu <liuchang0812@gmail.com> | 2017-11-28 13:10:04 +0100 |
commit | e4f3dd4a68bbc7903b30405172705e3938f13201 (patch) | |
tree | 31e9bb0ea74d106f98f8fce046cd80b67c63badb /src/rgw/rgw_common.cc | |
parent | Merge pull request #19182 from cbodley/wip-beast-v124 (diff) | |
download | ceph-e4f3dd4a68bbc7903b30405172705e3938f13201.tar.xz ceph-e4f3dd4a68bbc7903b30405172705e3938f13201.zip |
rgw: move {camecase, lowercase}_dash_http_attr functions to rgw_common
Signed-off-by: Chang Liu <liuchang0812@gmail.com>
Diffstat (limited to 'src/rgw/rgw_common.cc')
-rw-r--r-- | src/rgw/rgw_common.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 56a354a3faa..a743e7c02e7 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -1895,3 +1895,56 @@ bool match_policy(boost::string_view pattern, boost::string_view input, last_pos_input = cur_pos_input + 1; } } + +/* + * make attrs look-like-this + * converts underscores to dashes + */ +string lowercase_dash_http_attr(const string& orig) +{ + const char *s = orig.c_str(); + char buf[orig.size() + 1]; + buf[orig.size()] = '\0'; + + for (size_t i = 0; i < orig.size(); ++i, ++s) { + switch (*s) { + case '_': + buf[i] = '-'; + break; + default: + buf[i] = tolower(*s); + } + } + return string(buf); +} + +/* + * make attrs Look-Like-This + * converts underscores to dashes + */ +string camelcase_dash_http_attr(const string& orig) +{ + const char *s = orig.c_str(); + char buf[orig.size() + 1]; + buf[orig.size()] = '\0'; + + bool last_sep = true; + + for (size_t i = 0; i < orig.size(); ++i, ++s) { + switch (*s) { + case '_': + case '-': + buf[i] = '-'; + last_sep = true; + break; + default: + if (last_sep) { + buf[i] = toupper(*s); + } else { + buf[i] = tolower(*s); + } + last_sep = false; + } + } + return string(buf); +} |