Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /***************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <iostream>
31 : : #include <string.h>
32 : :
33 : : #include <libexttextcat/textcat.h>
34 : : #include <altstrfunc.hxx>
35 : : #include <guess.hxx>
36 : :
37 : : using namespace std;
38 : :
39 : 0 : Guess::Guess()
40 : : {
41 : 0 : language_str = DEFAULT_LANGUAGE;
42 : 0 : country_str = DEFAULT_COUNTRY;
43 : 0 : encoding_str = DEFAULT_ENCODING;
44 : 0 : }
45 : :
46 : : /*
47 : : * this use a char * string to build the guess object
48 : : * a string like those is made as : [language-country-encoding]...
49 : : *
50 : : */
51 : :
52 : 0 : Guess::Guess(const char * guess_str)
53 : : {
54 : 0 : Guess();
55 : :
56 : 0 : string lang;
57 : 0 : string country;
58 : 0 : string enc;
59 : :
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 : 0 : if(strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN) != 0
66 : : &&
67 : 0 : strcmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT) != 0)
68 : : {
69 : :
70 : 0 : int current_pointer = 0;
71 : :
72 : : //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
73 : 0 : while(!isSeparator(guess_str[current_pointer])){
74 : 0 : current_pointer++;
75 : : }
76 : 0 : current_pointer++;
77 : :
78 : : //this is to pick up the language ( the "en" from "[en-US-utf8]" )
79 : 0 : while(!isSeparator(guess_str[current_pointer])){
80 : 0 : lang+=guess_str[current_pointer];
81 : 0 : current_pointer++;
82 : : }
83 : 0 : current_pointer++;
84 : :
85 : : //this is to pick up the country ( the "US" from "[en-US-utf8]" )
86 : 0 : while(!isSeparator(guess_str[current_pointer])){
87 : 0 : country+=guess_str[current_pointer];
88 : 0 : current_pointer++;
89 : : }
90 : 0 : current_pointer++;
91 : :
92 : : //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
93 : 0 : while(!isSeparator(guess_str[current_pointer])){
94 : 0 : enc+=guess_str[current_pointer];
95 : 0 : current_pointer++;
96 : : }
97 : :
98 : 0 : if(lang!=""){//if not we use the default value
99 : 0 : language_str=lang;
100 : : }
101 : 0 : country_str=country;
102 : :
103 : 0 : if(enc!=""){//if not we use the default value
104 : 0 : encoding_str=enc;
105 : : }
106 : 0 : }
107 : 0 : }
108 : :
109 : 0 : Guess::~Guess()
110 : : {
111 : 0 : }
112 : :
113 : 0 : string Guess::GetLanguage()
114 : : {
115 : 0 : return language_str;
116 : : }
117 : :
118 : 0 : string Guess::GetCountry()
119 : : {
120 : 0 : return country_str;
121 : : }
122 : :
123 : 0 : string Guess::GetEncoding()
124 : : {
125 : 0 : return encoding_str;
126 : : }
127 : :
128 : 0 : bool Guess::operator==(string lang)
129 : : {
130 : 0 : string toString;
131 : 0 : toString += GetLanguage();
132 : 0 : toString += "-";
133 : 0 : toString += GetCountry();
134 : 0 : toString += "-";
135 : 0 : toString += GetEncoding();
136 : 0 : return start(toString, lang);
137 : 0 : }
138 : :
139 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|