diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index 4174d42..75e82f0 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -7461,3 +7461,40 @@ std::string join(const StringVector &sv,const std::string &delimiter) return result; } +QCString integerToAlpha(int n, bool upper) +{ + QCString result; + int residual = n; + + char modVal[2]; + modVal[1] = 0; + while (residual > 0) + { + modVal[0] = (upper ? 'A': 'a') + (residual-1)%26; + result = modVal + result; + residual = (residual-1) / 26; + } + return result; +} + +QCString integerToRoman(int n, bool upper) +{ + static const char *str_romans_upper[] = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; + static const char *str_romans_lower[] = { "m", "cm", "d", "cd", "c", "xc", "l", "xl", "x", "ix", "v", "iv", "i" }; + static const int values[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; + static const char **str_romans = upper ? str_romans_upper : str_romans_lower; + + QCString result; + int residual = n; + + for (int i = 0; i < 13; ++i) + { + while (residual - values[i] >= 0) + { + result += str_romans[i]; + residual -= values[i]; + } + } + + return result; +} |