34 #ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
35 #define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
37 #include "src/compiler/config.h"
46 namespace grpc_ruby_generator {
49 inline std::vector<grpc::string> &Split(
const grpc::string &s,
char delim,
50 std::vector<grpc::string> *elems) {
51 std::stringstream ss(s);
53 while (getline(ss, item, delim)) {
54 elems->push_back(item);
60 inline std::vector<grpc::string> Split(
const grpc::string &s,
char delim) {
61 std::vector<grpc::string> elems;
62 Split(s, delim, &elems);
67 inline grpc::string Replace(grpc::string s,
const grpc::string &from,
68 const grpc::string &to) {
69 size_t start_pos = s.find(from);
70 if (start_pos == grpc::string::npos) {
73 s.replace(start_pos, from.length(), to);
78 inline grpc::string ReplaceAll(grpc::string s,
const grpc::string &search,
79 const grpc::string &replace) {
81 while ((pos = s.find(search, pos)) != grpc::string::npos) {
82 s.replace(pos, search.length(), replace);
83 pos += replace.length();
89 inline bool ReplacePrefix(grpc::string *s,
const grpc::string &from,
90 const grpc::string &to) {
91 size_t start_pos = s->find(from);
92 if (start_pos == grpc::string::npos || start_pos != 0) {
95 s->replace(start_pos, from.length(), to);
100 inline grpc::string CapitalizeFirst(grpc::string s) {
104 s[0] = ::toupper(s[0]);
109 inline grpc::string RubyTypeOf(
const grpc::string &a_type,
110 const grpc::string &package) {
111 grpc::string res(a_type);
112 ReplacePrefix(&res, package,
"");
113 ReplacePrefix(&res,
".",
"");
114 if (res.find(
'.') == grpc::string::npos) {
117 std::vector<grpc::string> prefixes_and_type = Split(res,
'.');
118 for (
unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
122 if (i < prefixes_and_type.size() - 1) {
123 res += CapitalizeFirst(prefixes_and_type[i]);
125 res += prefixes_and_type[i];
134 #endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H