/src/libreoffice/vcl/inc/graphic/DetectorTools.hxx
Line | Count | Source |
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 | | |
13 | | #include <rtl/string.hxx> |
14 | | |
15 | | #include <vector> |
16 | | |
17 | | namespace vcl |
18 | | { |
19 | | const char* matchArray(const char* pSource, sal_Int32 nSourceSize, const char* pSearch, |
20 | | sal_Int32 nSearchSize) |
21 | 98.0k | { |
22 | 11.1M | for (sal_Int32 increment = 0; increment <= (nSourceSize - nSearchSize); ++increment) |
23 | 11.1M | { |
24 | 11.1M | bool bMatch = true; |
25 | | // search both arrays if they match |
26 | 22.4M | for (sal_Int32 index = 0; index < nSearchSize && bMatch; ++index) |
27 | 11.2M | { |
28 | 11.2M | if (pSource[index] != pSearch[index]) |
29 | 11.1M | bMatch = false; |
30 | 11.2M | } |
31 | | // match has been found |
32 | 11.1M | if (bMatch) |
33 | 23.0k | return pSource; |
34 | 11.1M | pSource++; |
35 | 11.1M | } |
36 | 75.0k | return nullptr; |
37 | 98.0k | } |
38 | | |
39 | | const char* matchArrayWithString(const char* pSource, sal_Int32 nSourceSize, OString const& rString) |
40 | 43.1k | { |
41 | 43.1k | return matchArray(pSource, nSourceSize, rString.getStr(), rString.getLength()); |
42 | 43.1k | } |
43 | | |
44 | | bool checkArrayForMatchingStrings(const char* pSource, sal_Int32 nSourceSize, |
45 | | std::vector<OString> const& rStrings) |
46 | 83.4k | { |
47 | 83.4k | if (rStrings.empty()) |
48 | 0 | return false; |
49 | 83.4k | if (rStrings.size() < 2) |
50 | 28.7k | return matchArrayWithString(pSource, nSourceSize, rStrings[0]) != nullptr; |
51 | | |
52 | 54.6k | const char* pBegin = pSource; |
53 | 54.6k | const char* pCurrent = pSource; |
54 | 54.6k | for (OString const& rString : rStrings) |
55 | 54.9k | { |
56 | 54.9k | sal_Int32 nCurrentSize = nSourceSize - sal_Int32(pCurrent - pBegin); |
57 | 54.9k | pCurrent = matchArray(pCurrent, nCurrentSize, rString.getStr(), rString.getLength()); |
58 | 54.9k | if (pCurrent == nullptr) |
59 | 54.6k | return false; |
60 | 54.9k | } |
61 | 0 | return true; |
62 | 54.6k | } |
63 | | } |
64 | | |
65 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |