MCPcopy Create free account
hub / github.com/Tracktion/choc / demonstrateStringUtilities

Function demonstrateStringUtilities

examples/text_processing.cpp:23–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21};
22
23void demonstrateStringUtilities()
24{
25 std::cout << "\n=== String Utilities Demo ===\n";
26
27 std::string text = " Hello, World! This is a test string. ";
28 std::cout << "Original: '" << text << "'\n";
29
30 // Trimming operations
31 std::cout << "Trimmed: '" << choc::text::trim (text) << "'\n";
32 std::cout << "Left trimmed: '" << choc::text::trimStart (text) << "'\n";
33 std::cout << "Right trimmed: '" << choc::text::trimEnd (text) << "'\n";
34
35 // Case operations
36 std::string testCase = "Hello World";
37 std::cout << "Original: " << testCase << "\n";
38 std::cout << "Uppercase: " << choc::text::toUpperCase (testCase) << "\n";
39 std::cout << "Lowercase: " << choc::text::toLowerCase (testCase) << "\n";
40
41 // String manipulation
42 std::string target = "The quick brown fox jumps over the lazy dog";
43 std::cout << "\nString replacement demo:\n";
44 std::cout << "Original: " << target << "\n";
45 std::cout << "Replace 'fox' with 'cat': "
46 << choc::text::replace (target, "fox", "cat") << "\n";
47 std::cout << "Replace all 'the' with 'a': "
48 << choc::text::replace (target, "the", "a") << "\n";
49
50 // String testing
51 std::cout << "\nString testing:\n";
52 std::cout << "Contains 'quick': " << choc::text::contains (target, "quick") << "\n";
53 std::cout << "Starts with 'The': " << choc::text::startsWith (target, "The") << "\n";
54 std::cout << "Ends with 'dog': " << choc::text::endsWith (target, "dog") << "\n";
55
56 // Splitting
57 std::string csv = "apple,banana,cherry,date,elderberry";
58 auto fruits = choc::text::splitString (csv, ',', false);
59 std::cout << "\nSplit '" << csv << "' by comma:\n";
60 for (size_t i = 0; i < fruits.size(); ++i)
61 {
62 std::cout << " " << i << ": '" << fruits[i] << "'\n";
63 }
64
65 // Joining
66 std::vector<std::string> words = {"Hello", "beautiful", "world"};
67 std::cout << "Join words with ' ': " << choc::text::joinStrings (words, " ") << "\n";
68 std::cout << "Join words with ' - ': " << choc::text::joinStrings (words, " - ") << "\n";
69}
70
71void demonstrateUTF8()
72{

Callers 1

mainFunction · 0.85

Calls 12

trimFunction · 0.85
trimStartFunction · 0.85
trimEndFunction · 0.85
toUpperCaseFunction · 0.85
toLowerCaseFunction · 0.85
replaceFunction · 0.85
containsFunction · 0.85
startsWithFunction · 0.85
endsWithFunction · 0.85
splitStringFunction · 0.85
joinStringsFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected