LCOV - code coverage report
Current view: top level - sc/inc - stringutil.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 1 100.0 %
Date: 2014-11-03 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          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             : #ifndef INCLUDED_SC_INC_STRINGUTIL_HXX
      21             : #define INCLUDED_SC_INC_STRINGUTIL_HXX
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : #include "scdllapi.h"
      25             : #include <i18nlangtag/lang.h>
      26             : 
      27             : class SvNumberFormatter;
      28             : 
      29             : /**
      30             :  * Store parameters used in the ScDocument::SetString() method.  Various
      31             :  * options for string-setting operation are specified herein.
      32             :  */
      33             : struct SC_DLLPUBLIC ScSetStringParam
      34             : {
      35             :     enum TextFormatPolicy
      36             :     {
      37             :         /**
      38             :          * Set Text number format no matter what the input string is.
      39             :          */
      40             :         Always,
      41             : 
      42             :         /**
      43             :          * Set Text number format only when the input string is considered a
      44             :          * special number but we only want to detect a simple number.
      45             :          */
      46             :         SpecialNumberOnly,
      47             : 
      48             :         /**
      49             :          * Never set Text number format.
      50             :          */
      51             :         Never
      52             :     };
      53             : 
      54             :     /**
      55             :      * Stores the pointer to the number formatter instance to be used during
      56             :      * number format detection.  The caller must manage the life cycle of the
      57             :      * instance.
      58             :      */
      59             :     SvNumberFormatter* mpNumFormatter;
      60             : 
      61             :     /**
      62             :      * When true, we try to detect special number format (dates etc) from the
      63             :      * input string, when false, we only try to detect a basic decimal number
      64             :      * format.
      65             :      */
      66             :     bool mbDetectNumberFormat;
      67             : 
      68             :     /**
      69             :      * Determine when to set the 'Text' number format to the cell where the
      70             :      * input string is being set.
      71             :      */
      72             :     TextFormatPolicy meSetTextNumFormat;
      73             : 
      74             :     /**
      75             :      * When true, treat input with a leading apostrophe as an escape character
      76             :      * for a numeric value content, to treat the numeric value as a text. When
      77             :      * false, the whole string input including the leading apostrophe will be
      78             :      * entered literally as string.
      79             :      */
      80             :     bool mbHandleApostrophe;
      81             : 
      82             :     ScSetStringParam();
      83             : 
      84             :     /**
      85             :      * Call this whenever you need to unconditionally set input as text, no
      86             :      * matter what the input is.
      87             :      */
      88             :     void setTextInput();
      89             : 
      90             :     /**
      91             :      * Call this whenever you need to maximize the chance of input being
      92             :      * detected as a numeric value (numbers, dates, times etc).
      93             :      */
      94             :     void setNumericInput();
      95             : };
      96             : 
      97        9740 : struct ScInputStringType
      98             : {
      99             :     enum StringType { Unknown = 0, Text, Formula, Number };
     100             : 
     101             :     StringType meType;
     102             : 
     103             :     OUString maText;
     104             :     double mfValue;
     105             :     short mnFormatType;
     106             : };
     107             : 
     108             : class ScStringUtil
     109             : {
     110             : public:
     111             : 
     112             :     /**
     113             :      * Check if a given string is a simple decimal number (e.g. 12.345). We
     114             :      * don't do any elaborate parsing here; we only check for the simplest
     115             :      * case of decimal number format.
     116             :      *
     117             :      * Note that preceding and trailing spaces are ignored during parsing.
     118             :      *
     119             :      * @param rStr string to parse
     120             :      * @param dsep decimal separator
     121             :      * @param gsep group separator (aka thousands separator)
     122             :      * @param rVal value of successfully parsed number
     123             :      *
     124             :      * @return true if the string is a valid number, false otherwise.
     125             :      */
     126             :     static bool parseSimpleNumber(
     127             :         const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal);
     128             : 
     129             :     static bool parseSimpleNumber(
     130             :         const char* p, size_t n, char dsep, char gsep, double& rVal);
     131             : 
     132             :     static sal_Int32 SC_DLLPUBLIC GetQuotedTokenCount(const OUString &rIn, const OUString& rQuotedPairs, sal_Unicode cTok = ';' );
     133             :     static OUString  SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString& rQuotedPairs,
     134             :                                         sal_Unicode cTok,  sal_Int32& rIndex );
     135             : 
     136             :     static bool SC_DLLPUBLIC isMultiline( const OUString& rStr );
     137             : 
     138             :     static ScInputStringType parseInputString(
     139             :         SvNumberFormatter& rFormatter, const OUString& rStr, LanguageType eLang );
     140             : };
     141             : 
     142             : #endif
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10