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