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 187475 : codemaker::UnoType::Sort codemaker::UnoType::getSort(rtl::OString const & type)
30 : {
31 187475 : return type == "void" ? SORT_VOID
32 171954 : : type == "boolean" ? SORT_BOOLEAN
33 160505 : : type == "byte" ? SORT_BYTE
34 157461 : : type == "short" ? SORT_SHORT
35 139068 : : type == "unsigned short" ? SORT_UNSIGNED_SHORT
36 138361 : : type == "long" ? SORT_LONG
37 98742 : : type == "unsigned long" ? SORT_UNSIGNED_LONG
38 98341 : : type == "hyper" ? SORT_HYPER
39 97411 : : type == "unsigned hyper" ? SORT_UNSIGNED_HYPER
40 97312 : : type == "float" ? SORT_FLOAT
41 96607 : : type == "double" ? SORT_DOUBLE
42 93065 : : type == "char" ? SORT_CHAR
43 92672 : : type == "string" ? SORT_STRING
44 67539 : : type == "type" ? SORT_TYPE
45 67041 : : type == "any" ? SORT_ANY
46 1763554 : : SORT_COMPLEX;
47 : }
48 :
49 19815 : bool codemaker::UnoType::isSequenceType(rtl::OString const & type) {
50 19815 : return !type.isEmpty() && type[0] == '[';
51 : }
52 :
53 344967 : rtl::OString codemaker::UnoType::decompose(
54 : rtl::OString const & type, sal_Int32 * rank,
55 : std::vector< rtl::OString > * arguments)
56 : {
57 344967 : sal_Int32 len = type.getLength();
58 344967 : sal_Int32 i = 0;
59 705449 : while (len - i > 1 && type[i + 1] == ']') {
60 15515 : i += 2;
61 : }
62 344967 : if (rank != 0) {
63 335142 : *rank = i / 2;
64 : }
65 344967 : sal_Int32 j = arguments == 0 ? -1 : type.indexOf('<', i);
66 344967 : if (j < 0) {
67 344468 : return type.copy(i);
68 : }
69 499 : sal_Int32 k = j;
70 1320 : do {
71 660 : ++k; // skip '<' or ','
72 660 : sal_Int32 l = k;
73 11272 : for (sal_Int32 level = 0; l != len; ++l) {
74 11272 : char c = type[l];
75 11272 : if (c == ',') {
76 247 : if (level == 0) {
77 161 : break;
78 : }
79 11025 : } else if (c == '<') {
80 136 : ++level;
81 10889 : } else if (c == '>') {
82 635 : if (level == 0) {
83 499 : break;
84 : }
85 136 : --level;
86 : }
87 : }
88 660 : arguments->push_back(type.copy(k, l - k));
89 660 : k = l;
90 660 : } while (k != len && type[k] != '>');
91 : OSL_ASSERT(k == len - 1 && type[k] == '>');
92 499 : return type.copy(i, j - i);
93 : }
94 :
95 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|