Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <iostream>
22 : #include <string.h>
23 :
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>
31 :
32 : /* Old textcat.h versions defined bad spelled constants. */
33 : #ifndef TEXTCAT_RESULT_UNKNOWN_STR
34 : #define TEXTCAT_RESULT_UNKNOWN_STR _TEXTCAT_RESULT_UNKOWN
35 : #endif
36 :
37 : #ifndef TEXTCAT_RESULT_SHORT_STR
38 : #define TEXTCAT_RESULT_SHORT_STR _TEXTCAT_RESULT_SHORT
39 : #endif
40 :
41 : using namespace std;
42 :
43 0 : Guess::Guess()
44 : {
45 0 : language_str = DEFAULT_LANGUAGE;
46 0 : country_str = DEFAULT_COUNTRY;
47 0 : encoding_str = DEFAULT_ENCODING;
48 0 : }
49 :
50 : /*
51 : * this use a char * string to build the guess object
52 : * a string like those is made as : [language-country-encoding]...
53 : *
54 : */
55 :
56 0 : Guess::Guess(const char * guess_str)
57 : {
58 0 : Guess();
59 :
60 0 : string lang;
61 0 : string country;
62 0 : string enc;
63 :
64 : //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
65 0 : if(strcmp((const char*)(guess_str + 1), TEXTCAT_RESULT_UNKNOWN_STR) != 0
66 0 : &&
67 0 : strcmp((const char*)(guess_str + 1), TEXTCAT_RESULT_SHORT_STR) != 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: */
|