MCPcopy Create free account
hub / github.com/DFHack/dfhack / capitalize_string_words

Function capitalize_string_words

library/MiscUtils.cpp:342–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342std::string capitalize_string_words(const std::string& str)
343{ // Cleaned up from g_src/basics.cpp, and returns new string
344 std::string out = str;
345 bool starting = true;
346 int32_t bracket_count = 0;
347 bool conf;
348
349 for (size_t s = 0; s < out.length(); s++)
350 {
351 if (out[s] == '[') { ++bracket_count; continue; }
352 else if (out[s] == ']') { --bracket_count; continue; }
353 else if (bracket_count > 0) continue;
354
355 conf = false;
356 if (!starting)
357 {
358 if (out[s - 1] == ' ' || out[s - 1] == '\"')
359 conf = true;
360 // Discount single quote if it isn't preceded by space, comma, or nothing
361 else if (out[s - 1] == '\'' && s >= 2 && (out[s - 2] == ' ' || out[s - 2] == ','))
362 conf = true;
363 }
364
365 if (starting || conf)
366 { // Capitalize
367 out[s] = toupper_cp437(out[s]);
368 starting = false;
369 }
370 }
371
372 return out;
373}
374
375bool word_wrap(std::vector<std::string> *out, const std::string &str, size_t line_length,
376 word_wrap_whitespace_mode mode)

Callers 2

capitalizeStringWordsFunction · 0.85
get_item_type_strFunction · 0.85

Calls 2

toupper_cp437Function · 0.85
lengthMethod · 0.80

Tested by

no test coverage detected