1b0844812SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b0844812SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b0844812SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b0844812SAndrew Rist * distributed with this work for additional information
6b0844812SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b0844812SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b0844812SAndrew Rist * "License"); you may not use this file except in compliance
9b0844812SAndrew Rist * with the License. You may obtain a copy of the License at
10b0844812SAndrew Rist *
11b0844812SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b0844812SAndrew Rist *
13b0844812SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b0844812SAndrew Rist * software distributed under the License is distributed on an
15b0844812SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b0844812SAndrew Rist * KIND, either express or implied. See the License for the
17b0844812SAndrew Rist * specific language governing permissions and limitations
18b0844812SAndrew Rist * under the License.
19b0844812SAndrew Rist *
20b0844812SAndrew Rist *************************************************************/
21b0844812SAndrew Rist
22b0844812SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*c4c42a0eSDamjan Jovanovic #include "precompiled_guesslang.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <iostream>
28cdf0e10cSrcweir #include <string.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <libtextcat/textcat.h>
31cdf0e10cSrcweir #include <altstrfunc.hxx>
32cdf0e10cSrcweir #include <guess.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir using namespace std;
35cdf0e10cSrcweir
Guess()36cdf0e10cSrcweir Guess::Guess()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir language_str = DEFAULT_LANGUAGE;
39cdf0e10cSrcweir country_str = DEFAULT_COUNTRY;
40cdf0e10cSrcweir encoding_str = DEFAULT_ENCODING;
41cdf0e10cSrcweir }
42cdf0e10cSrcweir
43cdf0e10cSrcweir /*
44cdf0e10cSrcweir * this use a char * string to build the guess object
45cdf0e10cSrcweir * a string like those is made as : [language-country-encoding]...
46cdf0e10cSrcweir *
47cdf0e10cSrcweir */
48cdf0e10cSrcweir
Guess(char * guess_str)49cdf0e10cSrcweir Guess::Guess(char * guess_str)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir Guess();
52cdf0e10cSrcweir
53cdf0e10cSrcweir string lang;
54cdf0e10cSrcweir string country;
55cdf0e10cSrcweir string enc;
56cdf0e10cSrcweir
57cdf0e10cSrcweir //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
58cdf0e10cSrcweir // if(strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN, strlen(_TEXTCAT_RESULT_UNKOWN)) != 0
59cdf0e10cSrcweir // &&
60cdf0e10cSrcweir // strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT, strlen(_TEXTCAT_RESULT_SHORT)) != 0)
61cdf0e10cSrcweir // {
62cdf0e10cSrcweir if(strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN) != 0
63cdf0e10cSrcweir &&
64cdf0e10cSrcweir strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT) != 0)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir
67cdf0e10cSrcweir int current_pointer = 0;
68cdf0e10cSrcweir
69cdf0e10cSrcweir //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
70cdf0e10cSrcweir while(!isSeparator(guess_str[current_pointer])){
71cdf0e10cSrcweir current_pointer++;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir current_pointer++;
74cdf0e10cSrcweir
75cdf0e10cSrcweir //this is to pick up the language ( the "en" from "[en-US-utf8]" )
76cdf0e10cSrcweir while(!isSeparator(guess_str[current_pointer])){
77cdf0e10cSrcweir lang+=guess_str[current_pointer];
78cdf0e10cSrcweir current_pointer++;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir current_pointer++;
81cdf0e10cSrcweir
82cdf0e10cSrcweir //this is to pick up the country ( the "US" from "[en-US-utf8]" )
83cdf0e10cSrcweir while(!isSeparator(guess_str[current_pointer])){
84cdf0e10cSrcweir country+=guess_str[current_pointer];
85cdf0e10cSrcweir current_pointer++;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir current_pointer++;
88cdf0e10cSrcweir
89cdf0e10cSrcweir //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
90cdf0e10cSrcweir while(!isSeparator(guess_str[current_pointer])){
91cdf0e10cSrcweir enc+=guess_str[current_pointer];
92cdf0e10cSrcweir current_pointer++;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir if(lang!=""){//if not we use the default value
96cdf0e10cSrcweir language_str=lang;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir country_str=country;
99cdf0e10cSrcweir
100cdf0e10cSrcweir if(enc!=""){//if not we use the default value
101cdf0e10cSrcweir encoding_str=enc;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir }
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
~Guess()106cdf0e10cSrcweir Guess::~Guess(){}
107cdf0e10cSrcweir
GetLanguage()108cdf0e10cSrcweir string Guess::GetLanguage()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir return language_str;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
GetCountry()113cdf0e10cSrcweir string Guess::GetCountry()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir return country_str;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
GetEncoding()118cdf0e10cSrcweir string Guess::GetEncoding()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir return encoding_str;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
operator ==(string lang)123cdf0e10cSrcweir bool Guess::operator==(string lang)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir string toString;
126cdf0e10cSrcweir toString += GetLanguage();
127cdf0e10cSrcweir toString += "-";
128cdf0e10cSrcweir toString += GetCountry();
129cdf0e10cSrcweir toString += "-";
130cdf0e10cSrcweir toString += GetEncoding();
131cdf0e10cSrcweir return start(toString, lang);
132cdf0e10cSrcweir }
133