| 1026 | size_t Key(const std::string &str) { return Key(str.c_str(), str.size()); } |
| 1027 | |
| 1028 | size_t String(const char *str, size_t len) { |
| 1029 | auto reset_to = buf_.size(); |
| 1030 | auto sloc = CreateBlob(str, len, 1, FBT_STRING); |
| 1031 | if (flags_ & BUILDER_FLAG_SHARE_STRINGS) { |
| 1032 | StringOffset so(sloc, len); |
| 1033 | auto it = string_pool.find(so); |
| 1034 | if (it != string_pool.end()) { |
| 1035 | // Already in the buffer. Remove string we just serialized, and use |
| 1036 | // existing offset instead. |
| 1037 | buf_.resize(reset_to); |
| 1038 | sloc = it->first; |
| 1039 | stack_.back().u_ = sloc; |
| 1040 | } else { |
| 1041 | string_pool.insert(so); |
| 1042 | } |
| 1043 | } |
| 1044 | return sloc; |
| 1045 | } |
| 1046 | size_t String(const char *str) { return String(str, strlen(str)); } |
| 1047 | size_t String(const std::string &str) { |
| 1048 | return String(str.c_str(), str.size()); |