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

Function positionToLocation

src/string.cpp:158–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156
157
158Location positionToLocation(const std::string& s, size_t pos) {
159 if (pos > s.size())
160 pos = s.size();
161
162 // Count number of newlines until pos
163 size_t line = 0;
164 size_t linePos = 0;
165 for (size_t i = 0; i < pos; i++) {
166 if (s[i] == '\n') {
167 line++;
168 linePos = i + 1;
169 }
170 }
171
172 // Count number of codepoints from line until pos
173 size_t column = 0;
174 for (size_t i = linePos; i < pos;) {
175 i = UTF8NextCodepoint(s, i);
176 column++;
177 }
178
179 return {line, column};
180}
181
182
183size_t locationToPosition(const std::string& s, Location location) {

Callers 1

onSelectKeyMethod · 0.85

Calls 2

UTF8NextCodepointFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected