LibreOffice Module vcl (master) 1
DetectorTools.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
11#pragma once
12
13namespace vcl
14{
15const char* matchArray(const char* pSource, sal_Int32 nSourceSize, const char* pSearch,
16 sal_Int32 nSearchSize)
17{
18 for (sal_Int32 increment = 0; increment <= (nSourceSize - nSearchSize); ++increment)
19 {
20 bool bMatch = true;
21 // search both arrays if they match
22 for (sal_Int32 index = 0; index < nSearchSize && bMatch; ++index)
23 {
24 if (pSource[index] != pSearch[index])
25 bMatch = false;
26 }
27 // match has been found
28 if (bMatch)
29 return pSource;
30 pSource++;
31 }
32 return nullptr;
33}
34
35const char* matchArrayWithString(const char* pSource, sal_Int32 nSourceSize, OString const& rString)
36{
37 return matchArray(pSource, nSourceSize, rString.getStr(), rString.getLength());
38}
39
40bool checkArrayForMatchingStrings(const char* pSource, sal_Int32 nSourceSize,
41 std::vector<OString> const& rStrings)
42{
43 if (rStrings.empty())
44 return false;
45 if (rStrings.size() < 2)
46 return matchArrayWithString(pSource, nSourceSize, rStrings[0]) != nullptr;
47
48 const char* pBegin = pSource;
49 const char* pCurrent = pSource;
50 for (OString const& rString : rStrings)
51 {
52 sal_Int32 nCurrentSize = nSourceSize - sal_Int32(pCurrent - pBegin);
53 pCurrent = matchArray(pCurrent, nCurrentSize, rString.getStr(), rString.getLength());
54 if (pCurrent == nullptr)
55 return false;
56 }
57 return true;
58}
59}
60
61/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
index
const char * matchArray(const char *pSource, sal_Int32 nSourceSize, const char *pSearch, sal_Int32 nSearchSize)
bool checkArrayForMatchingStrings(const char *pSource, sal_Int32 nSourceSize, std::vector< OString > const &rStrings)
const char * matchArrayWithString(const char *pSource, sal_Int32 nSourceSize, OString const &rString)