LibreOffice Module formula (master) 1
grammar.cxx
Go to the documentation of this file.
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#include <formula/grammar.hxx>
21#include <cassert>
22
23namespace formula {
24
25FormulaGrammar::Grammar FormulaGrammar::mapAPItoGrammar( const bool bEnglish, const bool bXML )
26{
27 Grammar eGrammar;
28 if (bEnglish && bXML)
29 eGrammar = GRAM_PODF;
30 else if (bEnglish && !bXML)
31 eGrammar = GRAM_API;
32 else if (!bEnglish && bXML)
33 eGrammar = GRAM_NATIVE_ODF;
34 else // (!bEnglish && !bXML)
35 eGrammar = GRAM_NATIVE;
36 return eGrammar;
37}
38
40{
41 switch (eGrammar)
42 {
43 case GRAM_ODFF :
44 case GRAM_PODF :
45 case GRAM_ENGLISH :
46 case GRAM_NATIVE :
47 case GRAM_ODFF_UI :
48 case GRAM_ODFF_A1 :
49 case GRAM_PODF_UI :
50 case GRAM_PODF_A1 :
51 case GRAM_NATIVE_UI :
52 case GRAM_NATIVE_ODF :
58 case GRAM_OOXML :
59 case GRAM_API :
60 return true;
61 default:
62 return extractFormulaLanguage( eGrammar) == GRAM_EXTERNAL;
63 }
64}
65
67{
68 if (bEnglish)
69 return static_cast<Grammar>( eGrammar | kEnglishBit);
70 else
71 return static_cast<Grammar>( eGrammar & ~kEnglishBit);
72}
73
75{
76 bool bEnglish = isEnglish( eGrammar);
77 Grammar eGram = static_cast<Grammar>(
78 extractFormulaLanguage( eGrammar) |
79 ((eConv + kConventionOffset) << kConventionShift));
80 eGram = setEnglishBit( eGram, bEnglish);
81 assert( isSupported( eGram));
82 return eGram;
83}
84
85}
86
87/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static Grammar mapAPItoGrammar(const bool bEnglish, const bool bXML)
Compatibility helper for old "bCompileEnglish, bCompileXML" API calls to obtain the new grammar.
Definition: grammar.cxx:25
static bool isSupported(const Grammar eGrammar)
Definition: grammar.cxx:39
static const int kConventionShift
Definition: grammar.hxx:57
static sal_Int32 extractFormulaLanguage(const Grammar eGrammar)
Definition: grammar.hxx:175
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
Definition: grammar.cxx:74
static const int kEnglishBit
Definition: grammar.hxx:59
static bool isEnglish(const Grammar eGrammar)
If English parsing/formatting is associated with a grammar.
Definition: grammar.hxx:164
Grammar
Values encoding the formula language plus address reference convention plus English parsing/formattin...
Definition: grammar.hxx:68
@ GRAM_API
API English with A1 reference style, unbracketed.
Definition: grammar.hxx:147
@ GRAM_NATIVE_XL_R1C1
Native with Excel R1C1 reference style.
Definition: grammar.hxx:123
@ GRAM_NATIVE_ODF
Native with ODF A1 bracketed references. Not very useful but supported.
Definition: grammar.hxx:115
@ GRAM_NATIVE
Native with default A1 reference style.
Definition: grammar.hxx:87
@ GRAM_NATIVE_XL_A1
Native with Excel A1 reference style.
Definition: grammar.hxx:119
@ GRAM_ENGLISH_XL_OOX
English with Excel OOXML reference style.
Definition: grammar.hxx:137
@ GRAM_ENGLISH
English with default A1 reference style.
Definition: grammar.hxx:82
@ GRAM_NATIVE_UI
Native with reference style as set in UI, may be A1 or R1C1.
Definition: grammar.hxx:111
@ GRAM_ODFF
ODFF with default ODF A1 bracketed references.
Definition: grammar.hxx:72
@ GRAM_PODF_UI
ODF 1.1 with reference style as set in UI, may be A1 or R1C1.
Definition: grammar.hxx:101
@ GRAM_PODF
ODF 1.1 with default ODF A1 bracketed references.
Definition: grammar.hxx:77
@ GRAM_ENGLISH_XL_A1
English with Excel A1 reference style.
Definition: grammar.hxx:127
@ GRAM_PODF_A1
ODF 1.1 with A1 reference style, unbracketed.
Definition: grammar.hxx:106
@ GRAM_ODFF_UI
ODFF with reference style as set in UI, may be A1 or R1C1.
Definition: grammar.hxx:91
@ GRAM_EXTERNAL
OpCodeMap set by external filter and merged with reference convention plus English bit on top.
Definition: grammar.hxx:160
@ GRAM_ODFF_A1
ODFF with A1 reference style, unbracketed.
Definition: grammar.hxx:96
@ GRAM_ENGLISH_XL_R1C1
English with Excel R1C1 reference style.
Definition: grammar.hxx:132
@ GRAM_OOXML
Excel OOXML with Excel OOXML reference style.
Definition: grammar.hxx:142
static const int kConventionOffset
CONV_UNSPECIFIED is a negative value!
Definition: grammar.hxx:55
static Grammar setEnglishBit(const Grammar eGrammar, const bool bEnglish)
Definition: grammar.cxx:66