MCPcopy Create free account
hub / github.com/VCVRack/Rack / truncatePrefix

Function truncatePrefix

src/string.cpp:100–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98
99
100std::string truncatePrefix(const std::string& s, size_t maxCodepoints) {
101 if (s.empty() || maxCodepoints == 0)
102 return "";
103
104 size_t pos = s.size();
105 for (size_t i = 0; i < maxCodepoints; i++) {
106 // If remaining bytes are less than remaining codepoints, the string can't possibly be truncated.
107 if (pos <= maxCodepoints - i)
108 return s;
109
110 pos = UTF8PrevCodepoint(s, pos);
111 // Check if at beginning
112 if (pos == 0)
113 return s;
114 }
115
116 return s.substr(pos);
117}
118
119
120std::string ellipsize(const std::string& s, size_t maxCodepoints) {

Callers 1

ellipsizePrefixFunction · 0.85

Calls 3

UTF8PrevCodepointFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected