summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2012-11-26 11:03:24 -0600
committerNorbert Thiebaud <nthiebaud@gmail.com>2012-11-27 23:00:04 -0600
commitad6f9f2f00df27eec2fc6e640eb1a662644de6a4 (patch)
tree62431406830814a99c0815202a2761a7465b6414 /svl
parentc7709b460394283fd5b1d2779b6af3585f80a991 (diff)
String=>OUString of svl's urihelper
Change-Id: Ib4d9175ce4661140a147962b8f45be40f800d85a
Diffstat (limited to 'svl')
-rw-r--r--svl/inc/svl/urihelper.hxx57
-rw-r--r--svl/qa/unit/test_URIHelper.cxx8
-rw-r--r--svl/source/misc/urihelper.cxx156
3 files changed, 100 insertions, 121 deletions
diff --git a/svl/inc/svl/urihelper.hxx b/svl/inc/svl/urihelper.hxx
index 6e0746b28eeb..c00d5331472a 100644
--- a/svl/inc/svl/urihelper.hxx
+++ b/svl/inc/svl/urihelper.hxx
@@ -32,7 +32,7 @@ namespace com { namespace sun { namespace star {
namespace uno { class XComponentContext; }
namespace uri { class XUriReference; }
} } }
-namespace rtl { class OUString; }
+
class CharClass;
//============================================================================
@@ -51,19 +51,16 @@ namespace URIHelper {
existence (see URIHelper::GetMaybeFileHdl), or use bCheckFileExists = false
if you want to generate file URLs without checking for their existence.
*/
-SVL_DLLPUBLIC rtl::OUString
-SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
- rtl::OUString const & rTheRelURIRef,
- Link const & rMaybeFileHdl = Link(),
- bool bCheckFileExists = true,
- bool bIgnoreFragment = false,
- INetURLObject::EncodeMechanism eEncodeMechanism
- = INetURLObject::WAS_ENCODED,
- INetURLObject::DecodeMechanism eDecodeMechanism
- = INetURLObject::DECODE_TO_IURI,
- rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
- bool bRelativeNonURIs = false,
- INetURLObject::FSysStyle eStyle = INetURLObject::FSYS_DETECT);
+SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
+ OUString const & rTheRelURIRef,
+ Link const & rMaybeFileHdl = Link(),
+ bool bCheckFileExists = true,
+ bool bIgnoreFragment = false,
+ INetURLObject::EncodeMechanism eEncodeMechanism = INetURLObject::WAS_ENCODED,
+ INetURLObject::DecodeMechanism eDecodeMechanism = INetURLObject::DECODE_TO_IURI,
+ rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
+ bool bRelativeNonURIs = false,
+ INetURLObject::FSysStyle eStyle = INetURLObject::FSYS_DETECT);
//============================================================================
SVL_DLLPUBLIC void SetMaybeFileHdl(Link const & rTheMaybeFileHdl);
@@ -119,20 +116,17 @@ normalizedMakeRelative(
@deprecated
No code should rely on the default component context.
*/
-SVL_DLLPUBLIC rtl::OUString simpleNormalizedMakeRelative(
- rtl::OUString const & baseUriReference, rtl::OUString const & uriReference);
+SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative( OUString const & baseUriReference,
+ OUString const & uriReference);
//============================================================================
-SVL_DLLPUBLIC rtl::OUString
-FindFirstURLInText(rtl::OUString const & rText,
- xub_StrLen & rBegin,
- xub_StrLen & rEnd,
- CharClass const & rCharClass,
- INetURLObject::EncodeMechanism eMechanism
- = INetURLObject::WAS_ENCODED,
- rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
- INetURLObject::FSysStyle eStyle
- = INetURLObject::FSYS_DETECT);
+SVL_DLLPUBLIC OUString FindFirstURLInText(OUString const & rText,
+ sal_Int32 & rBegin,
+ sal_Int32 & rEnd,
+ CharClass const & rCharClass,
+ INetURLObject::EncodeMechanism eMechanism = INetURLObject::WAS_ENCODED,
+ rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
+ INetURLObject::FSysStyle eStyle = INetURLObject::FSYS_DETECT);
//============================================================================
/** Remove any password component from both absolute and relative URLs.
@@ -160,13 +154,10 @@ FindFirstURLInText(rtl::OUString const & rText,
@return The input URI with any password component removed.
*/
-SVL_DLLPUBLIC rtl::OUString
-removePassword(rtl::OUString const & rURI,
- INetURLObject::EncodeMechanism eEncodeMechanism
- = INetURLObject::WAS_ENCODED,
- INetURLObject::DecodeMechanism eDecodeMechanism
- = INetURLObject::DECODE_TO_IURI,
- rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
+SVL_DLLPUBLIC OUString removePassword(OUString const & rURI,
+ INetURLObject::EncodeMechanism eEncodeMechanism = INetURLObject::WAS_ENCODED,
+ INetURLObject::DecodeMechanism eDecodeMechanism = INetURLObject::DECODE_TO_IURI,
+ rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
}
#endif // SVTOOLS_URIHELPER_HXX
diff --git a/svl/qa/unit/test_URIHelper.cxx b/svl/qa/unit/test_URIHelper.cxx
index 822b5a212e01..179ef3a2289e 100644
--- a/svl/qa/unit/test_URIHelper.cxx
+++ b/svl/qa/unit/test_URIHelper.cxx
@@ -301,8 +301,8 @@ void Test::testFindFirstURLInText() {
struct Data {
char const * input;
char const * result;
- xub_StrLen begin;
- xub_StrLen end;
+ sal_Int32 begin;
+ sal_Int32 end;
};
static Data const tests[] = {
{ "...ftp://bla.bla.bla/blubber/...",
@@ -390,8 +390,8 @@ void Test::testFindFirstURLInText() {
CharClass charClass( m_context, LanguageTag( com::sun::star::lang::Locale("en", "US", "")));
for (std::size_t i = 0; i < SAL_N_ELEMENTS(tests); ++i) {
rtl::OUString input(rtl::OUString::createFromAscii(tests[i].input));
- xub_StrLen begin = 0;
- xub_StrLen end = static_cast< xub_StrLen >(input.getLength());
+ sal_Int32 begin = 0;
+ sal_Int32 end = input.getLength();
rtl::OUString result(
URIHelper::FindFirstURLInText(input, begin, end, charClass));
bool ok = tests[i].result == 0
diff --git a/svl/source/misc/urihelper.cxx b/svl/source/misc/urihelper.cxx
index 2ae2890f4c63..35bd41ed265d 100644
--- a/svl/source/misc/urihelper.cxx
+++ b/svl/source/misc/urihelper.cxx
@@ -53,17 +53,16 @@ using namespace com::sun::star;
//
//============================================================================
-rtl::OUString
-URIHelper::SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
- rtl::OUString const & rTheRelURIRef,
- Link const & rMaybeFileHdl,
- bool bCheckFileExists,
- bool bIgnoreFragment,
- INetURLObject::EncodeMechanism eEncodeMechanism,
- INetURLObject::DecodeMechanism eDecodeMechanism,
- rtl_TextEncoding eCharset,
- bool bRelativeNonURIs,
- INetURLObject::FSysStyle eStyle)
+OUString URIHelper::SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
+ OUString const & rTheRelURIRef,
+ Link const & rMaybeFileHdl,
+ bool bCheckFileExists,
+ bool bIgnoreFragment,
+ INetURLObject::EncodeMechanism eEncodeMechanism,
+ INetURLObject::DecodeMechanism eDecodeMechanism,
+ rtl_TextEncoding eCharset,
+ bool bRelativeNonURIs,
+ INetURLObject::FSysStyle eStyle)
{
// Backwards compatibility:
if (!rTheRelURIRef.isEmpty() && rTheRelURIRef[0] == '#')
@@ -71,8 +70,7 @@ URIHelper::SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
INetURLObject aAbsURIRef;
if (rTheBaseURIRef.HasError())
- aAbsURIRef.
- SetSmartURL(rTheRelURIRef, eEncodeMechanism, eCharset, eStyle);
+ aAbsURIRef. SetSmartURL(rTheRelURIRef, eEncodeMechanism, eCharset, eStyle);
else
{
bool bWasAbsolute;
@@ -98,7 +96,7 @@ URIHelper::SmartRel2Abs(INetURLObject const & rTheBaseURIRef,
bool bMaybeFile = false;
if (rMaybeFileHdl.IsSet())
{
- UniString aFilePath(rTheRelURIRef);
+ OUString aFilePath(rTheRelURIRef);
bMaybeFile = rMaybeFileHdl.Call(&aFilePath) != 0;
}
if (!bMaybeFile)
@@ -148,9 +146,8 @@ bool isAbsoluteHierarchicalUriReference(
// any other prefix URL of the given URL, too:
enum Result { Success, GeneralFailure, SpecificFailure };
-Result normalizePrefix(
- css::uno::Reference< css::ucb::XUniversalContentBroker > const & broker,
- rtl::OUString const & uri, rtl::OUString * normalized)
+Result normalizePrefix( css::uno::Reference< css::ucb::XUniversalContentBroker > const & broker,
+ OUString const & uri, OUString * normalized)
{
OSL_ASSERT(broker.is() && normalized != 0);
css::uno::Reference< css::ucb::XContent > content;
@@ -182,16 +179,16 @@ Result normalizePrefix(
return Success;
}
-rtl::OUString normalize(
+OUString normalize(
css::uno::Reference< css::ucb::XUniversalContentBroker > const & broker,
css::uno::Reference< css::uri::XUriReferenceFactory > const & uriFactory,
- rtl::OUString const & uriReference)
+ OUString const & uriReference)
{
// normalizePrefix can potentially fail (a typically example being a file
// URL that denotes a non-existing resource); in such a case, try to
// normalize as long a prefix of the given URL as possible (i.e., normalize
// all the existing directories within the path):
- rtl::OUString normalized;
+ OUString normalized;
sal_Int32 n = uriReference.indexOf('#');
normalized = n == -1 ? uriReference : uriReference.copy(0, n);
switch (normalizePrefix(broker, normalized, &normalized)) {
@@ -212,14 +209,14 @@ rtl::OUString normalize(
if (count < 2) {
return uriReference;
}
- rtl::OUStringBuffer head(ref->getScheme());
+ OUStringBuffer head(ref->getScheme());
head.append(static_cast< sal_Unicode >(':'));
if (ref->hasAuthority()) {
head.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
head.append(ref->getAuthority());
}
for (sal_Int32 i = count - 1; i > 0; --i) {
- rtl::OUStringBuffer buf(head);
+ OUStringBuffer buf(head);
for (sal_Int32 j = 0; j < i; ++j) {
buf.append(static_cast< sal_Unicode >('/'));
buf.append(ref->getPathSegment(j));
@@ -271,7 +268,7 @@ rtl::OUString normalize(
css::uno::Reference< css::uri::XUriReference >
URIHelper::normalizedMakeRelative(
css::uno::Reference< css::uno::XComponentContext > const & context,
- rtl::OUString const & baseUriReference, rtl::OUString const & uriReference)
+ OUString const & baseUriReference, OUString const & uriReference)
{
OSL_ASSERT(context.is());
css::uno::Reference< css::ucb::XUniversalContentBroker > broker(
@@ -284,8 +281,8 @@ URIHelper::normalizedMakeRelative(
true, false);
}
-rtl::OUString URIHelper::simpleNormalizedMakeRelative(
- rtl::OUString const & baseUriReference, rtl::OUString const & uriReference)
+OUString URIHelper::simpleNormalizedMakeRelative(
+ OUString const & baseUriReference, OUString const & uriReference)
{
com::sun::star::uno::Reference< com::sun::star::uri::XUriReference > rel(
URIHelper::normalizedMakeRelative(
@@ -302,22 +299,22 @@ rtl::OUString URIHelper::simpleNormalizedMakeRelative(
namespace {
-inline xub_StrLen nextChar(UniString const & rStr, xub_StrLen nPos)
+inline sal_Int32 nextChar(OUString const & rStr, sal_Int32 nPos)
{
- return INetMIME::isHighSurrogate(rStr.GetChar(nPos))
- && rStr.Len() - nPos >= 2
- && INetMIME::isLowSurrogate(rStr.GetChar(nPos + 1)) ?
- nPos + 2 : nPos + 1;
+ return INetMIME::isHighSurrogate(rStr[nPos])
+ && rStr.getLength() - nPos >= 2
+ && INetMIME::isLowSurrogate(rStr[nPos + 1]) ?
+ nPos + 2 : nPos + 1;
}
-bool isBoundary1(CharClass const & rCharClass, UniString const & rStr,
- xub_StrLen nPos, xub_StrLen nEnd)
+bool isBoundary1(CharClass const & rCharClass, OUString const & rStr,
+ sal_Int32 nPos, sal_Int32 nEnd)
{
if (nPos == nEnd)
return true;
if (rCharClass.isLetterNumeric(rStr, nPos))
return false;
- switch (rStr.GetChar(nPos))
+ switch (rStr[nPos])
{
case '$':
case '%':
@@ -332,14 +329,14 @@ bool isBoundary1(CharClass const & rCharClass, UniString const & rStr,
}
}
-bool isBoundary2(CharClass const & rCharClass, UniString const & rStr,
- xub_StrLen nPos, xub_StrLen nEnd)
+bool isBoundary2(CharClass const & rCharClass, OUString const & rStr,
+ sal_Int32 nPos, sal_Int32 nEnd)
{
if (nPos == nEnd)
return true;
if (rCharClass.isLetterNumeric(rStr, nPos))
return false;
- switch (rStr.GetChar(nPos))
+ switch (rStr[nPos])
{
case '!':
case '#':
@@ -367,11 +364,11 @@ bool isBoundary2(CharClass const & rCharClass, UniString const & rStr,
}
}
-bool checkWChar(CharClass const & rCharClass, UniString const & rStr,
- xub_StrLen * pPos, xub_StrLen * pEnd, bool bBackslash = false,
+bool checkWChar(CharClass const & rCharClass, OUString const & rStr,
+ sal_Int32 * pPos, sal_Int32 * pEnd, bool bBackslash = false,
bool bPipe = false)
{
- sal_Unicode c = rStr.GetChar(*pPos);
+ sal_Unicode c = rStr[*pPos];
if (INetMIME::isUSASCII(c))
{
static sal_uInt8 const aMap[128]
@@ -433,29 +430,28 @@ bool checkWChar(CharClass const & rCharClass, UniString const & rStr,
return false;
}
-sal_uInt32 scanDomain(UniString const & rStr, xub_StrLen * pPos,
- xub_StrLen nEnd)
+sal_uInt32 scanDomain(OUString const & rStr, sal_Int32 * pPos,
+ sal_Int32 nEnd)
{
- sal_Unicode const * pBuffer = rStr.GetBuffer();
+ sal_Unicode const * pBuffer = rStr.getStr();
sal_Unicode const * p = pBuffer + *pPos;
sal_uInt32 nLabels = INetURLObject::scanDomain(p, pBuffer + nEnd, false);
- *pPos = sal::static_int_cast< xub_StrLen >(p - pBuffer);
+ *pPos = sal::static_int_cast< sal_Int32 >(p - pBuffer);
return nLabels;
}
}
-rtl::OUString
-URIHelper::FindFirstURLInText(rtl::OUString const & rText,
- xub_StrLen & rBegin,
- xub_StrLen & rEnd,
- CharClass const & rCharClass,
- INetURLObject::EncodeMechanism eMechanism,
- rtl_TextEncoding eCharset,
- INetURLObject::FSysStyle eStyle)
+OUString URIHelper::FindFirstURLInText(OUString const & rText,
+ sal_Int32 & rBegin,
+ sal_Int32 & rEnd,
+ CharClass const & rCharClass,
+ INetURLObject::EncodeMechanism eMechanism,
+ rtl_TextEncoding eCharset,
+ INetURLObject::FSysStyle eStyle)
{
if (!(rBegin <= rEnd && rEnd <= rText.getLength()))
- return rtl::OUString();
+ return OUString();
// Search for the first substring of [rBegin..rEnd[ that matches any of the
// following productions (for which the appropriate style bit is set in
@@ -523,26 +519,24 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
bool bBoundary1 = true;
bool bBoundary2 = true;
- for (xub_StrLen nPos = rBegin; nPos != rEnd; nPos = nextChar(rText, nPos))
+ for (sal_Int32 nPos = rBegin; nPos != rEnd; nPos = nextChar(rText, nPos))
{
sal_Unicode c = rText[nPos];
if (bBoundary1)
{
if (INetMIME::isAlpha(c))
{
- xub_StrLen i = nPos;
- INetProtocol eScheme
- = INetURLObject::CompareProtocolScheme(UniString(rText, i,
- rEnd));
+ sal_Int32 i = nPos;
+ INetProtocol eScheme = INetURLObject::CompareProtocolScheme(rText.copy(i, rEnd - i));
if (eScheme == INET_PROT_FILE) // 2nd
{
while (rText[i++] != ':') ;
- xub_StrLen nPrefixEnd = i;
- xub_StrLen nUriEnd = i;
+ sal_Int32 nPrefixEnd = i;
+ sal_Int32 nUriEnd = i;
while (i != rEnd
&& checkWChar(rCharClass, rText, &i, &nUriEnd, true,
true)) ;
- if (i != nPrefixEnd && rText[i] == '#')
+ if (i != nPrefixEnd && rText[i] == (sal_Unicode)'#')
{
++i;
while (i != rEnd
@@ -551,8 +545,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
if (nUriEnd != nPrefixEnd
&& isBoundary1(rCharClass, rText, nUriEnd, rEnd))
{
- INetURLObject aUri(UniString(rText, nPos,
- nUriEnd - nPos),
+ INetURLObject aUri(rText.copy(nPos, nUriEnd - nPos),
INET_PROT_FILE, eMechanism, eCharset,
eStyle);
if (!aUri.HasError())
@@ -567,8 +560,8 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
else if (eScheme != INET_PROT_NOT_VALID) // 1st
{
while (rText[i++] != ':') ;
- xub_StrLen nPrefixEnd = i;
- xub_StrLen nUriEnd = i;
+ sal_Int32 nPrefixEnd = i;
+ sal_Int32 nUriEnd = i;
while (i != rEnd
&& checkWChar(rCharClass, rText, &i, &nUriEnd)) ;
if (i != nPrefixEnd && rText[i] == '#')
@@ -581,8 +574,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
&& (isBoundary1(rCharClass, rText, nUriEnd, rEnd)
|| rText[nUriEnd] == '\\'))
{
- INetURLObject aUri(UniString(rText, nPos,
- nUriEnd - nPos),
+ INetURLObject aUri(rText.copy(nPos, nUriEnd - nPos),
INET_PROT_HTTP, eMechanism,
eCharset);
if (!aUri.HasError())
@@ -615,7 +607,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
// (note that rText.GetChar(nPos + 3) is guaranteed to be
// valid)
{
- xub_StrLen nUriEnd = i;
+ sal_Int32 nUriEnd = i;
if (i != rEnd && rText[i] == '/')
{
nUriEnd = ++i;
@@ -631,8 +623,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
if (isBoundary1(rCharClass, rText, nUriEnd, rEnd)
|| rText[nUriEnd] == '\\')
{
- INetURLObject aUri(UniString(rText, nPos,
- nUriEnd - nPos),
+ INetURLObject aUri(rText.copy(nPos, nUriEnd - nPos),
INET_PROT_HTTP, eMechanism,
eCharset);
if (!aUri.HasError())
@@ -651,13 +642,12 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
|| rText[nPos + 2] == '\\')) // 7th, 8th
{
i = nPos + 3;
- xub_StrLen nUriEnd = i;
+ sal_Int32 nUriEnd = i;
while (i != rEnd
&& checkWChar(rCharClass, rText, &i, &nUriEnd)) ;
if (isBoundary1(rCharClass, rText, nUriEnd, rEnd))
{
- INetURLObject aUri(UniString(rText, nPos,
- nUriEnd - nPos),
+ INetURLObject aUri(rText.copy(nPos, nUriEnd - nPos),
INET_PROT_FILE,
INetURLObject::ENCODE_ALL,
RTL_TEXTENCODING_UTF8,
@@ -676,18 +666,17 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
&& rText[nPos] == '\\'
&& rText[nPos + 1] == '\\') // 6th
{
- xub_StrLen i = nPos + 2;
+ sal_Int32 i = nPos + 2;
sal_uInt32 nLabels = scanDomain(rText, &i, rEnd);
if (nLabels >= 1 && i != rEnd && rText[i] == '\\')
{
- xub_StrLen nUriEnd = ++i;
+ sal_Int32 nUriEnd = ++i;
while (i != rEnd
&& checkWChar(rCharClass, rText, &i, &nUriEnd,
true)) ;
if (isBoundary1(rCharClass, rText, nUriEnd, rEnd))
{
- INetURLObject aUri(UniString(rText, nPos,
- nUriEnd - nPos),
+ INetURLObject aUri(rText.copy(nPos, nUriEnd - nPos),
INET_PROT_FILE,
INetURLObject::ENCODE_ALL,
RTL_TEXTENCODING_UTF8,
@@ -706,7 +695,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
if (bBoundary2 && INetMIME::isAtomChar(c)) // 5th
{
bool bDot = false;
- for (xub_StrLen i = nPos + 1; i != rEnd; ++i)
+ for (sal_Int32 i = nPos + 1; i != rEnd; ++i)
{
sal_Unicode c2 = rText[i];
if (INetMIME::isAtomChar(c2))
@@ -724,7 +713,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
if (nLabels >= 1
&& isBoundary1(rCharClass, rText, i, rEnd))
{
- INetURLObject aUri(UniString(rText, nPos, i - nPos),
+ INetURLObject aUri(rText.copy(nPos, i - nPos),
INET_PROT_MAILTO,
INetURLObject::ENCODE_ALL);
if (!aUri.HasError())
@@ -744,7 +733,7 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
bBoundary2 = isBoundary2(rCharClass, rText, nPos, rEnd);
}
rBegin = rEnd;
- return rtl::OUString();
+ return OUString();
}
//============================================================================
@@ -753,11 +742,10 @@ URIHelper::FindFirstURLInText(rtl::OUString const & rText,
//
//============================================================================
-rtl::OUString
-URIHelper::removePassword(rtl::OUString const & rURI,
- INetURLObject::EncodeMechanism eEncodeMechanism,
- INetURLObject::DecodeMechanism eDecodeMechanism,
- rtl_TextEncoding eCharset)
+OUString URIHelper::removePassword(OUString const & rURI,
+ INetURLObject::EncodeMechanism eEncodeMechanism,
+ INetURLObject::DecodeMechanism eDecodeMechanism,
+ rtl_TextEncoding eCharset)
{
INetURLObject aObj(rURI, eEncodeMechanism, eCharset);
return aObj.HasError() ?