bump product version to 4.1.6.2
[LibreOffice.git] / lingucomponent / source / languageguessing / guess.cxx
blob6d7b61e175152230b1780613fbbf45c975bbd40b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <iostream>
22 #include <string.h>
24 #ifdef SYSTEM_LIBEXTTEXTCAT
25 #include <libexttextcat/textcat.h>
26 #else
27 #include <textcat.h>
28 #endif
29 #include <altstrfunc.hxx>
30 #include <guess.hxx>
32 using namespace std;
34 Guess::Guess()
36 language_str = DEFAULT_LANGUAGE;
37 country_str = DEFAULT_COUNTRY;
38 encoding_str = DEFAULT_ENCODING;
42 * this use a char * string to build the guess object
43 * a string like those is made as : [language-country-encoding]...
47 Guess::Guess(const char * guess_str)
49 Guess();
51 string lang;
52 string country;
53 string enc;
55 //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
56 // if(strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKNOWN, strlen(_TEXTCAT_RESULT_UNKNOWN)) != 0
57 // &&
58 // strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT, strlen(_TEXTCAT_RESULT_SHORT)) != 0)
59 // {
60 // FIXME just a temporary check until new version with renamed macros deployed
61 #if EXTTEXTCAT_VERSION_MAJOR > 3 || (EXTTEXTCAT_VERSION_MAJOR == 3 && (EXTTEXTCAT_VERSION_MINOR > 4 || (EXTTEXTCAT_VERSION_MINOR == 4 && (EXTTEXTCAT_VERSION_MICRO >= 1))))
62 if(strcmp((const char*)(guess_str + 1), TEXTCAT_RESULT_UNKNOWN_STR) != 0
64 strcmp((const char*)(guess_str + 1), TEXTCAT_RESULT_SHORT_STR) != 0)
65 #else
66 if(strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN) != 0
68 strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT) != 0)
69 #endif
72 int current_pointer = 0;
74 //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
75 while(!isSeparator(guess_str[current_pointer])){
76 current_pointer++;
78 current_pointer++;
80 //this is to pick up the language ( the "en" from "[en-US-utf8]" )
81 while(!isSeparator(guess_str[current_pointer])){
82 lang+=guess_str[current_pointer];
83 current_pointer++;
85 current_pointer++;
87 //this is to pick up the country ( the "US" from "[en-US-utf8]" )
88 while(!isSeparator(guess_str[current_pointer])){
89 country+=guess_str[current_pointer];
90 current_pointer++;
92 current_pointer++;
94 //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
95 while(!isSeparator(guess_str[current_pointer])){
96 enc+=guess_str[current_pointer];
97 current_pointer++;
100 if(lang!=""){//if not we use the default value
101 language_str=lang;
103 country_str=country;
105 if(enc!=""){//if not we use the default value
106 encoding_str=enc;
111 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);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */