MCPcopy Create free account
hub / github.com/apache/impala / TruncateUp

Function TruncateUp

be/src/util/string-util.cc:37–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37Status TruncateUp(const string& str, int32_t max_length, string* result) {
38 DCHECK(result != nullptr);
39 if (str.length() <= max_length) {
40 *result = str;
41 return Status::OK();
42 }
43
44 *result = str.substr(0, max_length);
45 int i = max_length - 1;
46 while (i > 0 && static_cast<int32_t>((*result)[i]) == -1) {
47 (*result)[i] += 1;
48 --i;
49 }
50 // We convert it to unsigned because signed overflow results in undefined behavior.
51 unsigned char uch = static_cast<unsigned char>((*result)[i]);
52 uch += 1;
53 (*result)[i] = uch;
54 if (i == 0 && (*result)[i] == 0) {
55 return Status("TruncateUp() couldn't increase string.");
56 }
57 result->resize(i + 1);
58 return Status::OK();
59}
60
61bool CommaSeparatedContains(const std::string& cs_list, const std::string& item) {
62 size_t pos = 0;

Callers 3

EvalTruncationFunction · 0.85
TESTFunction · 0.85

Calls 5

OKFunction · 0.85
substrMethod · 0.80
resizeMethod · 0.80
StatusClass · 0.70
lengthMethod · 0.45

Tested by 2

EvalTruncationFunction · 0.68
TESTFunction · 0.68