LCOV - code coverage report
Current view: top level - include/as2js - string.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2014-11-22 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifndef AS2JS_STRING_H
       2             : #define AS2JS_STRING_H
       3             : /* as2js/string.h -- written by Alexis WILKE for Made to Order Software Corp. (c) 2005-2014 */
       4             : 
       5             : /*
       6             : 
       7             : Copyright (c) 2005-2014 Made to Order Software Corp.
       8             : 
       9             : http://snapwebsites.org/project/as2js
      10             : 
      11             : Permission is hereby granted, free of charge, to any
      12             : person obtaining a copy of this software and
      13             : associated documentation files (the "Software"), to
      14             : deal in the Software without restriction, including
      15             : without limitation the rights to use, copy, modify,
      16             : merge, publish, distribute, sublicense, and/or sell
      17             : copies of the Software, and to permit persons to whom
      18             : the Software is furnished to do so, subject to the
      19             : following conditions:
      20             : 
      21             : The above copyright notice and this permission notice
      22             : shall be included in all copies or substantial
      23             : portions of the Software.
      24             : 
      25             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      26             : ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      27             : LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      28             : FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      29             : EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      30             : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      31             : WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      32             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      33             : SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      34             : SOFTWARE.
      35             : 
      36             : */
      37             : 
      38             : #include    "int64.h"
      39             : #include    "float64.h"
      40             : 
      41             : #include    <iostream>
      42             : #include    <string>
      43             : 
      44             : namespace as2js
      45             : {
      46             : 
      47             : // our character type, yes, it also becomes as String::value_type
      48             : // but at least this way we control the size outside of the class
      49             : typedef int32_t                                         as_char_t;
      50             : typedef controlled_vars::auto_init<as_char_t, 0>        zas_char_t;
      51             : 
      52             : // Our String type is a UCS-4 compatible string type
      53             : // Unfortunately, under MS-Windows wstring is 16 bits
      54  2267397204 : class String : public std::basic_string<as_char_t>
      55             : {
      56             : public:
      57             :     typedef controlled_vars::auto_init<size_type, 0>    zsize_type_t;
      58             : 
      59             :     // Unicode BOM character
      60             :     static as_char_t const  STRING_BOM = 0xFEFF;
      61             :     // Represents a continuation character (i.e. '\' + LineTerminatorSequence)
      62             :     static as_char_t const  STRING_CONTINUATION = -2;
      63             : 
      64             :     enum class conversion_result_t
      65             :     {
      66             :         STRING_GOOD    =  0,   // string conversion succeeded
      67             :         STRING_END     = -1,   // not enough data to form a character
      68             :         STRING_BAD     = -2,   // input is not valid (bad encoding sequence)
      69             :         STRING_INVALID = -3    // invalid character found (character is not between 0 and 0x10FFFF, or is a code point reserved for UTF-16 surrogates)
      70             :     };
      71             : 
      72             :                             String();
      73             :                             String(char const *str, int len = -1);
      74             :                             String(wchar_t const *str, int len = -1);
      75             :                             String(as_char_t const *str, int len = -1);
      76             :                             String(std::string const& str);
      77             :                             String(std::wstring const& str);
      78             :                             String(std::basic_string<as_char_t> const& str);
      79             : 
      80             :     String&                 operator = (char const *str);
      81             :     String&                 operator = (wchar_t const *str);
      82             :     String&                 operator = (as_char_t const *str);
      83             :     String&                 operator = (std::string const& str);
      84             :     String&                 operator = (std::wstring const& str);
      85             :     String&                 operator = (std::basic_string<as_char_t> const& str);
      86             : 
      87             :     bool                    operator == (char const *str) const;
      88             :     friend bool             operator == (char const *str, String const& string);
      89             :     bool                    operator != (char const *str) const;
      90             :     friend bool             operator != (char const *str, String const& string);
      91             : 
      92             :     String&                 operator += (char const *str);
      93             :     String&                 operator += (wchar_t const *str);
      94             :     String&                 operator += (as_char_t const *str);
      95             :     String&                 operator += (std::string const& str);
      96             :     String&                 operator += (std::wstring const& str);
      97             :     String&                 operator += (std::basic_string<as_char_t> const& str);
      98             : 
      99             :     String&                 operator += (as_char_t const c);
     100             :     String&                 operator += (char const c);
     101             :     String&                 operator += (wchar_t const c);
     102             : 
     103             :     bool                    valid() const;
     104             :     static bool             valid_character(as_char_t c);
     105             : 
     106             :     bool                    is_int64() const;
     107             :     bool                    is_float64() const;
     108             :     bool                    is_number() const;
     109             :     Int64::int64_type       to_int64() const;
     110             :     Float64::float64_type   to_float64() const;
     111             :     bool                    is_true() const;
     112             : 
     113             :     conversion_result_t     from_char(char const *str, int len = -1);
     114             :     conversion_result_t     from_wchar(wchar_t const *str, int len = -1);
     115             :     conversion_result_t     from_as_char(as_char_t const *str, int len = -1);
     116             :     conversion_result_t     from_utf8(char const *str, int len = -1);
     117             : 
     118             :     ssize_t                 utf8_length() const;
     119             :     std::string             to_utf8() const;
     120             : 
     121             :     String                  simplified() const;
     122             : };
     123             : 
     124             : std::ostream& operator << (std::ostream& out, String const& str);
     125             : 
     126             : 
     127             : }
     128             : // namespace as2js
     129             : 
     130             : #endif
     131             : // #ifndef AS2JS_STRING_H
     132             : 
     133             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.10