Contents

1
2
3
4
5
6
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

const std::string VOWEL_ASC_ENG = "aeiouAEIOU";

is_vowel_asc_eng()

Return true if input is contained in VOWEL_ASC_ENG.

1
2
3
4
> is_vowel_asc_eng("a")
1
> is_vowel_asc_eng("b")
0

1
2
3
bool is_vowel_asc_eng(char c) {
    return VOWEL_ASC_ENG.find(c) != std::string::npos;
}

last_nonblank()

Return last nonblank character of a string.

1
2
3
4
> last_nonblank("foobar"))
'r'
> last_nonblank("foobar "))
'r'

1
2
3
4
5
char last_nonblank(std::string s) {
    int len = s.length() - 1;
    while (std::isspace(s[len])) len--;
    return s[len];
}

toupper_s()

Convert a string to uppercase.

1
2
> toupper_s("foo")
'FOO'

1
2
3
4
std::string toupper_s(std::string s) {
    std::transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

toupper_subs()

Convert a substring to uppercase.

1
2
> toupper_subs("foobar", 1, 5)
'fOOBAr'

1
2
3
4
5
6
7
8
std::string toupper_subs(std::string s, int begin = -1, int end = 0) {
    int b = begin < 0 ? 0 : begin,
        e = !end ? s.length() : end;
    std::string subs = s.substr(b, e - b);
    std::transform(subs.begin(), subs.end(), subs.begin(), ::toupper);
    s.replace(b, e - b, subs);
    return s;
}