LCOV - code coverage report
Current view: top level - lingucomponent/source/languageguessing - guess.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 52 0.0 %
Date: 2014-04-14 Functions: 0 9 0.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             : #include <iostream>
      21             : #include <string.h>
      22             : 
      23             : #ifdef SYSTEM_LIBEXTTEXTCAT
      24             : #include <libexttextcat/textcat.h>
      25             : #else
      26             : #include <textcat.h>
      27             : #endif
      28             : #include <altstrfunc.hxx>
      29             : #include <guess.hxx>
      30             : 
      31             : /* Old textcat.h versions defined bad spelled constants. */
      32             : #ifndef TEXTCAT_RESULT_UNKNOWN_STR
      33             : #define TEXTCAT_RESULT_UNKNOWN_STR _TEXTCAT_RESULT_UNKOWN
      34             : #endif
      35             : 
      36             : #ifndef TEXTCAT_RESULT_SHORT_STR
      37             : #define TEXTCAT_RESULT_SHORT_STR _TEXTCAT_RESULT_SHORT
      38             : #endif
      39             : 
      40             : using namespace std;
      41             : 
      42           0 : Guess::Guess()
      43             : {
      44           0 :     language_str = DEFAULT_LANGUAGE;
      45           0 :     country_str = DEFAULT_COUNTRY;
      46           0 :     encoding_str = DEFAULT_ENCODING;
      47           0 : }
      48             : 
      49             : /*
      50             : * this use a char * string to build the guess object
      51             : * a string like those is made as : [language-country-encoding]...
      52             : *
      53             : */
      54           0 : Guess::Guess(const char * guess_str)
      55             : {
      56           0 :     Guess();
      57             : 
      58           0 :     string lang;
      59           0 :     string country;
      60           0 :     string enc;
      61             : 
      62             :     //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
      63           0 :     if(strcmp((const char*)(guess_str + 1), TEXTCAT_RESULT_UNKNOWN_STR) != 0
      64           0 :        &&
      65           0 :        strcmp((const char*)(guess_str + 1), TEXTCAT_RESULT_SHORT_STR) != 0)
      66             :     {
      67             : 
      68           0 :         int current_pointer = 0;
      69             : 
      70             :         //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
      71           0 :         while(!isSeparator(guess_str[current_pointer])){
      72           0 :             current_pointer++;
      73             :         }
      74           0 :         current_pointer++;
      75             : 
      76             :         //this is to pick up the language ( the "en" from "[en-US-utf8]" )
      77           0 :         while(!isSeparator(guess_str[current_pointer])){
      78           0 :             lang+=guess_str[current_pointer];
      79           0 :             current_pointer++;
      80             :         }
      81           0 :         current_pointer++;
      82             : 
      83             :         //this is to pick up the country ( the "US" from "[en-US-utf8]" )
      84           0 :         while(!isSeparator(guess_str[current_pointer])){
      85           0 :             country+=guess_str[current_pointer];
      86           0 :             current_pointer++;
      87             :         }
      88           0 :         current_pointer++;
      89             : 
      90             :         //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
      91           0 :         while(!isSeparator(guess_str[current_pointer])){
      92           0 :             enc+=guess_str[current_pointer];
      93           0 :             current_pointer++;
      94             :         }
      95             : 
      96           0 :         if(lang!=""){//if not we use the default value
      97           0 :             language_str=lang;
      98             :         }
      99           0 :         country_str=country;
     100             : 
     101           0 :         if(enc!=""){//if not we use the default value
     102           0 :             encoding_str=enc;
     103             :         }
     104           0 :     }
     105           0 : }
     106             : 
     107           0 : Guess::~Guess()
     108             : {
     109           0 : }
     110             : 
     111           0 : string Guess::GetLanguage()
     112             : {
     113           0 :     return language_str;
     114             : }
     115             : 
     116           0 : string Guess::GetCountry()
     117             : {
     118           0 :     return country_str;
     119             : }
     120             : 
     121           0 : string Guess::GetEncoding()
     122             : {
     123           0 :     return encoding_str;
     124             : }
     125             : 
     126           0 : bool Guess::operator==(string lang)
     127             : {
     128           0 :     string toString;
     129           0 :     toString += GetLanguage();
     130           0 :     toString += "-";
     131           0 :     toString += GetCountry();
     132           0 :     toString += "-";
     133           0 :     toString += GetEncoding();
     134           0 :     return start(toString, lang);
     135           0 : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10