1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_codemaker.hxx"
26
27 #include "codemaker/unotype.hxx"
28
29 #include "osl/diagnose.h"
30 #include "rtl/string.hxx"
31 #include "sal/types.h"
32
33 #include <vector>
34
getSort(rtl::OString const & type)35 codemaker::UnoType::Sort codemaker::UnoType::getSort(rtl::OString const & type)
36 {
37 return type == "void" ? SORT_VOID
38 : type == "boolean" ? SORT_BOOLEAN
39 : type == "byte" ? SORT_BYTE
40 : type == "short" ? SORT_SHORT
41 : type == "unsigned short" ? SORT_UNSIGNED_SHORT
42 : type == "long" ? SORT_LONG
43 : type == "unsigned long" ? SORT_UNSIGNED_LONG
44 : type == "hyper" ? SORT_HYPER
45 : type == "unsigned hyper" ? SORT_UNSIGNED_HYPER
46 : type == "float" ? SORT_FLOAT
47 : type == "double" ? SORT_DOUBLE
48 : type == "char" ? SORT_CHAR
49 : type == "string" ? SORT_STRING
50 : type == "type" ? SORT_TYPE
51 : type == "any" ? SORT_ANY
52 : SORT_COMPLEX;
53 }
54
isSequenceType(rtl::OString const & type)55 bool codemaker::UnoType::isSequenceType(rtl::OString const & type) {
56 return ( !type.isEmpty() && type[0] == '[' );
57 }
58
decompose(rtl::OString const & type,sal_Int32 * rank,std::vector<rtl::OString> * arguments)59 rtl::OString codemaker::UnoType::decompose(
60 rtl::OString const & type, sal_Int32 * rank,
61 std::vector< rtl::OString > * arguments)
62 {
63 sal_Int32 len = type.getLength();
64 sal_Int32 i = 0;
65 while (len - i > 1 && type[i + 1] == ']') {
66 i += 2;
67 }
68 if (rank != 0) {
69 *rank = i / 2;
70 }
71 sal_Int32 j = arguments == 0 ? -1 : type.indexOf('<', i);
72 if (j < 0) {
73 return type.copy(i);
74 }
75 sal_Int32 k = j;
76 do {
77 ++k; // skip '<' or ','
78 sal_Int32 l = k;
79 for (sal_Int32 level = 0; l != len; ++l) {
80 char c = type[l];
81 if (c == ',') {
82 if (level == 0) {
83 break;
84 }
85 } else if (c == '<') {
86 ++level;
87 } else if (c == '>') {
88 if (level == 0) {
89 break;
90 }
91 --level;
92 }
93 }
94 arguments->push_back(type.copy(k, l - k));
95 k = l;
96 } while (k != len && type[k] != '>');
97 OSL_ASSERT(k == len - 1 && type[k] == '>');
98 return type.copy(i, j - i);
99 }
100