24#include <osl/diagnose.h>
25#include <com/sun/star/lang/IllegalArgumentException.hpp>
26#include <rtl/character.hxx>
27#include <rtl/ustrbuf.hxx>
28#include <rtl/ustring.hxx>
38inline Regexp::Regexp(
Kind eTheKind, OUString aThePrefix,
39 bool bTheEmptyDomain, OUString aTheInfix,
41 OUString aTheReversePrefix):
43 m_aPrefix(
std::move(aThePrefix)),
44 m_aInfix(
std::move(aTheInfix)),
45 m_aReversePrefix(
std::move(aTheReversePrefix)),
46 m_bEmptyDomain(bTheEmptyDomain),
47 m_bTranslation(bTheTranslation)
57bool matchStringIgnoreCase(
sal_Unicode const ** pBegin,
59 OUString
const & rString)
66 if (pEnd - p < qEnd - q)
71 if (rtl::compareIgnoreAsciiCase(*p++, *q++) != 0)
84 sal_Unicode const * pEnd = pBegin + rString.getLength();
86 bool bMatches =
false;
89 if (matchStringIgnoreCase(&
p, pEnd,
m_aPrefix))
98 bMatches =
p == pEnd || *
p ==
'/' || *
p ==
'?' || *
p ==
'#';
104 if (
p == pEnd || *
p ==
'/' || *
p ==
'?' || *
p ==
'#')
111 if (matchStringIgnoreCase(&q, pEnd,
m_aInfix)
112 && (q == pEnd || *q ==
'/' || *q ==
'?' || *q ==
'#'))
122 if (c ==
'/' || c ==
'?' || c ==
'#')
135bool isScheme(OUString
const & rString,
bool bColon)
141 if (p != pEnd && rtl::isAsciiAlpha(*p))
147 if (!(rtl::isAsciiAlphanumeric(c)
148 || c ==
'+' || c ==
'-' || c ==
'.'))
149 return bColon && c ==
':' &&
p == pEnd;
154void appendStringLiteral(OUStringBuffer * pBuffer,
155 OUString
const & rString)
159 pBuffer->append(
'"');
165 if (c ==
'"' || c ==
'\\')
166 pBuffer->append(
'\\');
169 pBuffer->append(
'"');
188 aBuffer.append(
"(([/?#].*)?)");
202 return aBuffer.makeStringAndClear();
228 return aBuffer.makeStringAndClear();
236 char const * pString,
size_t nStringLength)
240 unsigned char const * q =
reinterpret_cast< unsigned char const *
>(pString);
241 unsigned char const * qEnd = q + nStringLength;
243 if (pEnd - p < qEnd - q)
263 if (p == pEnd || *p++ !=
'"')
279 if (c !=
'"' && c !=
'\\')
286 *pString =
aBuffer.makeStringAndClear();
296 if (isScheme(rRegexp,
false))
308 scanStringLiteral(&
p, pEnd, &aPrefix);
311 throw lang::IllegalArgumentException();
316 if (matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
".*")))
319 throw lang::IllegalArgumentException();
324 else if (matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"(.*)->")))
326 OUString aReversePrefix;
327 scanStringLiteral(&
p, pEnd, &aReversePrefix);
329 if (!matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"\\1"))
331 throw lang::IllegalArgumentException();
334 true, aReversePrefix);
336 else if (matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"([/?#].*)?")))
339 throw lang::IllegalArgumentException();
344 else if (matchString(&
p, pEnd,
345 RTL_CONSTASCII_STRINGPARAM(
"(([/?#].*)?)->")))
347 OUString aReversePrefix;
348 if (!(scanStringLiteral(&
p, pEnd, &aReversePrefix)
349 && matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"\\1"))
351 throw lang::IllegalArgumentException();
354 true, aReversePrefix);
359 if (
p != pEnd && *
p ==
'(')
365 if (!matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"[^/?#]")))
366 throw lang::IllegalArgumentException();
368 if (
p == pEnd || (*
p !=
'*' && *
p !=
'+'))
369 throw lang::IllegalArgumentException();
370 bool bEmptyDomain = *
p++ ==
'*';
373 scanStringLiteral(&
p, pEnd, &aInfix);
375 if (!matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"([/?#].*)?")))
376 throw lang::IllegalArgumentException();
378 OUString aReversePrefix;
380 && !(matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
")->"))
381 && scanStringLiteral(&
p, pEnd, &aReversePrefix)
382 && matchString(&
p, pEnd, RTL_CONSTASCII_STRINGPARAM(
"\\1"))))
383 throw lang::IllegalArgumentException();
386 throw lang::IllegalArgumentException();
389 bOpen, aReversePrefix);
OUString m_aReversePrefix
OUString getRegexp() const
Regexp(Kind eTheKind, OUString aThePrefix, bool bTheEmptyDomain, OUString aTheInfix, bool bTheTranslation, OUString aTheReversePrefix)
static Regexp parse(OUString const &rRegexp)
bool matches(OUString const &rString) const
std::unique_ptr< char[]> aBuffer