Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / lingucomponent / source / languageguessing / guess.cxx
blobf09bdecc6c0dde30d20225e356f37d774de19f38
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /***************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <iostream>
31 #include <string.h>
33 #include <libexttextcat/textcat.h>
34 #include <altstrfunc.hxx>
35 #include <guess.hxx>
37 using namespace std;
39 Guess::Guess()
41 language_str = DEFAULT_LANGUAGE;
42 country_str = DEFAULT_COUNTRY;
43 encoding_str = DEFAULT_ENCODING;
47 * this use a char * string to build the guess object
48 * a string like those is made as : [language-country-encoding]...
52 Guess::Guess(const char * guess_str)
54 Guess();
56 string lang;
57 string country;
58 string enc;
60 //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
61 // if(strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN, strlen(_TEXTCAT_RESULT_UNKOWN)) != 0
62 // &&
63 // strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT, strlen(_TEXTCAT_RESULT_SHORT)) != 0)
64 // {
65 if(strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN) != 0
67 strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT) != 0)
70 int current_pointer = 0;
72 //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
73 while(!isSeparator(guess_str[current_pointer])){
74 current_pointer++;
76 current_pointer++;
78 //this is to pick up the language ( the "en" from "[en-US-utf8]" )
79 while(!isSeparator(guess_str[current_pointer])){
80 lang+=guess_str[current_pointer];
81 current_pointer++;
83 current_pointer++;
85 //this is to pick up the country ( the "US" from "[en-US-utf8]" )
86 while(!isSeparator(guess_str[current_pointer])){
87 country+=guess_str[current_pointer];
88 current_pointer++;
90 current_pointer++;
92 //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
93 while(!isSeparator(guess_str[current_pointer])){
94 enc+=guess_str[current_pointer];
95 current_pointer++;
98 if(lang!=""){//if not we use the default value
99 language_str=lang;
101 country_str=country;
103 if(enc!=""){//if not we use the default value
104 encoding_str=enc;
109 Guess::~Guess()
113 string Guess::GetLanguage()
115 return language_str;
118 string Guess::GetCountry()
120 return country_str;
123 string Guess::GetEncoding()
125 return encoding_str;
128 bool Guess::operator==(string lang)
130 string toString;
131 toString += GetLanguage();
132 toString += "-";
133 toString += GetCountry();
134 toString += "-";
135 toString += GetEncoding();
136 return start(toString, lang);
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */