Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "codemaker/unotype.hxx"
22 :
23 : #include "osl/diagnose.h"
24 : #include "rtl/string.hxx"
25 : #include "sal/types.h"
26 :
27 : #include <vector>
28 :
29 271503 : OString codemaker::UnoType::decompose(
30 : OString const & type, sal_Int32 * rank,
31 : std::vector< OString > * arguments)
32 : {
33 271503 : sal_Int32 len = type.getLength();
34 271503 : sal_Int32 i = 0;
35 555719 : while (len - i > 1 && type[i + 1] == ']') {
36 12713 : i += 2;
37 : }
38 271503 : if (rank != 0) {
39 270903 : *rank = i / 2;
40 : }
41 271503 : sal_Int32 j = arguments == 0 ? -1 : type.indexOf('<', i);
42 271503 : if (j < 0) {
43 271007 : return type.copy(i);
44 : }
45 496 : sal_Int32 k = j;
46 654 : do {
47 654 : ++k; // skip '<' or ','
48 654 : sal_Int32 l = k;
49 11234 : for (sal_Int32 level = 0; l != len; ++l) {
50 11234 : char c = type[l];
51 11234 : if (c == ',') {
52 245 : if (level == 0) {
53 158 : break;
54 : }
55 10989 : } else if (c == '<') {
56 136 : ++level;
57 10853 : } else if (c == '>') {
58 632 : if (level == 0) {
59 496 : break;
60 : }
61 136 : --level;
62 : }
63 : }
64 654 : arguments->push_back(type.copy(k, l - k));
65 654 : k = l;
66 654 : } while (k != len && type[k] != '>');
67 : OSL_ASSERT(k == len - 1 && type[k] == '>');
68 496 : return type.copy(i, j - i);
69 : }
70 :
71 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|