Update ooo320-m1
[ooovba.git] / lingucomponent / source / languageguessing / guess.cxx
blob94ceb4da1ccfb9f974fc874f760567ca98e28dfb
1 /***************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: guess.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_lingucomponent.hxx"
34 #include <iostream>
35 #include <string.h>
37 #include <libtextcat/textcat.h>
38 #include <altstrfunc.hxx>
39 #include <guess.hxx>
41 using namespace std;
43 Guess::Guess()
45 language_str = DEFAULT_LANGUAGE;
46 country_str = DEFAULT_COUNTRY;
47 encoding_str = DEFAULT_ENCODING;
51 * this use a char * string to build the guess object
52 * a string like those is made as : [language-country-encoding]...
56 Guess::Guess(char * guess_str)
58 Guess();
60 string lang;
61 string country;
62 string enc;
64 //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
65 // if(strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN, strlen(_TEXTCAT_RESULT_UNKOWN)) != 0
66 // &&
67 // strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT, strlen(_TEXTCAT_RESULT_SHORT)) != 0)
68 // {
69 if(strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN) != 0
71 strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT) != 0)
74 int current_pointer = 0;
76 //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
77 while(!isSeparator(guess_str[current_pointer])){
78 current_pointer++;
80 current_pointer++;
82 //this is to pick up the language ( the "en" from "[en-US-utf8]" )
83 while(!isSeparator(guess_str[current_pointer])){
84 lang+=guess_str[current_pointer];
85 current_pointer++;
87 current_pointer++;
89 //this is to pick up the country ( the "US" from "[en-US-utf8]" )
90 while(!isSeparator(guess_str[current_pointer])){
91 country+=guess_str[current_pointer];
92 current_pointer++;
94 current_pointer++;
96 //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
97 while(!isSeparator(guess_str[current_pointer])){
98 enc+=guess_str[current_pointer];
99 current_pointer++;
102 if(lang!=""){//if not we use the default value
103 language_str=lang;
105 country_str=country;
107 if(enc!=""){//if not we use the default value
108 encoding_str=enc;
113 Guess::~Guess(){}
115 string Guess::GetLanguage()
117 return language_str;
120 string Guess::GetCountry()
122 return country_str;
125 string Guess::GetEncoding()
127 return encoding_str;
130 bool Guess::operator==(string lang)
132 string toString;
133 toString += GetLanguage();
134 toString += "-";
135 toString += GetCountry();
136 toString += "-";
137 toString += GetEncoding();
138 return start(toString, lang);