diff options
Diffstat (limited to 'comphelper/source/misc/string.cxx')
-rw-r--r-- | comphelper/source/misc/string.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index fc15b09f17a1..f59653130e06 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -417,6 +417,38 @@ sal_Int32 indexOfAny(OUString const& rIn, return -1; } +OUString setToken(const OUString& rIn, sal_Int32 nToken, sal_Unicode cTok, + const OUString& rNewToken) +{ + const sal_Unicode* pStr = rIn.getStr(); + sal_Int32 nLen = rIn.getLength(); + sal_Int32 nTok = 0; + sal_Int32 nFirstChar = 0; + sal_Int32 i = 0; + + // Determine token position and length + while ( i < nLen ) + { + // Increase token count if match + if (*pStr == cTok) + { + ++nTok; + + if (nTok == nToken) + nFirstChar = i+1; + else if (nTok > nToken) + break; + } + + ++pStr, + ++i; + } + + if (nTok >= nToken) + return rIn.replaceAt(nFirstChar, i-nFirstChar, rNewToken); + return rIn; +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |