LCOV - code coverage report
Current view: top level - libreoffice/workdir/unxlngi6.pro/UnpackedTarball/orcus/src/liborcus - gnumeric_helper.cpp (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 21 0.0 %
Date: 2012-12-17 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*************************************************************************
       2             :  *
       3             :  * Copyright (c) 2012 Markus Mohrhard
       4             :  *
       5             :  * Permission is hereby granted, free of charge, to any person
       6             :  * obtaining a copy of this software and associated documentation
       7             :  * files (the "Software"), to deal in the Software without
       8             :  * restriction, including without limitation the rights to use,
       9             :  * copy, modify, merge, publish, distribute, sublicense, and/or sell
      10             :  * copies of the Software, and to permit persons to whom the
      11             :  * Software is furnished to do so, subject to the following
      12             :  * conditions:
      13             :  *
      14             :  * The above copyright notice and this permission notice shall be
      15             :  * included in all copies or substantial portions of the Software.
      16             :  *
      17             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      18             :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
      19             :  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
      20             :  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
      21             :  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      22             :  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      23             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
      24             :  * OTHER DEALINGS IN THE SOFTWARE.
      25             :  *
      26             :  ************************************************************************/
      27             : 
      28             : #include "orcus/gnumeric/gnumeric_helper.hpp"
      29             : 
      30             : #include <cstdlib>
      31             : #include <vector>
      32             : #include <cassert>
      33             : 
      34             : namespace orcus {
      35             : 
      36             : using ::orcus::spreadsheet::color_elem_t;
      37             : 
      38             : namespace {
      39             : 
      40           0 : std::vector<pstring> split_string(pstring str, char sep)
      41             : {
      42             :     std::vector<pstring> ret;
      43             : 
      44             :     size_t len = 0;
      45             :     const char* start = str.get();
      46           0 :     for (size_t i = 0, n = str.size(); i < n; ++i)
      47             :     {
      48           0 :         if (str[i] == sep)
      49             :         {
      50           0 :             ret.push_back( pstring( start, len ) );
      51             :             len = 0;
      52             : 
      53             :             // if not at the end move the start string
      54           0 :             if (i < n-1)
      55           0 :                 start = start + len + 1;
      56             : 
      57             :         }
      58             :         else
      59           0 :             ++len;
      60             :     }
      61             : 
      62           0 :     return ret;
      63             : }
      64             : 
      65           0 : size_t parse_color_string(pstring str)
      66             : {
      67           0 :     unsigned long col_value = strtol( str.get(), NULL, 16 );
      68           0 :     col_value = col_value >> 8;
      69             :     // make sure that this actually worked
      70           0 :     assert( col_value <= 255 );
      71             : 
      72           0 :     return static_cast<color_elem_t>(col_value);
      73             : }
      74             : 
      75             : }
      76             : 
      77           0 : bool gnumeric_helper::parse_RGB_color_attribute(color_elem_t& red, color_elem_t& green, color_elem_t& blue, const pstring& attr)
      78             : {
      79           0 :     std::vector<pstring> color = split_string(attr, ':');
      80             : 
      81           0 :     if (color.size() != 3)
      82             :         return false;
      83             : 
      84           0 :     red = parse_color_string(color[0]);
      85           0 :     green = parse_color_string(color[1]);
      86           0 :     blue = parse_color_string(color[2]);
      87             : 
      88           0 :     return true;
      89             : }
      90             : 
      91           0 : }

Generated by: LCOV version 1.10