fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lingucomponent / source / languageguessing / guess.cxx
blobfa1e6f62b804804e1f6dfd4ae027b627eb237c42
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 .
20 #include <iostream>
21 #include <string.h>
23 #ifdef SYSTEM_LIBEXTTEXTCAT
24 #include <libexttextcat/textcat.h>
25 #else
26 #include <textcat.h>
27 #endif
28 #include <altstrfunc.hxx>
29 #include <guess.hxx>
31 /* Old textcat.h versions defined bad spelled constants. */
32 #ifndef TEXTCAT_RESULT_UNKNOWN_STR
33 #define TEXTCAT_RESULT_UNKNOWN_STR _TEXTCAT_RESULT_UNKOWN
34 #endif
36 #ifndef TEXTCAT_RESULT_SHORT_STR
37 #define TEXTCAT_RESULT_SHORT_STR _TEXTCAT_RESULT_SHORT
38 #endif
40 using namespace std;
42 Guess::Guess()
43 : language_str(DEFAULT_LANGUAGE)
44 , country_str(DEFAULT_COUNTRY)
45 , encoding_str(DEFAULT_ENCODING)
50 * this use a char * string to build the guess object
51 * a string like those is made as : [language-country-encoding]...
54 Guess::Guess(const char * guess_str)
55 : language_str(DEFAULT_LANGUAGE)
56 , country_str(DEFAULT_COUNTRY)
57 , encoding_str(DEFAULT_ENCODING)
59 string lang;
60 string country;
61 string enc;
63 //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
64 if(strcmp(guess_str + 1, TEXTCAT_RESULT_UNKNOWN_STR) != 0
66 strcmp(guess_str + 1, TEXTCAT_RESULT_SHORT_STR) != 0)
69 int current_pointer = 0;
71 //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
72 while(!isSeparator(guess_str[current_pointer])){
73 current_pointer++;
75 current_pointer++;
77 //this is to pick up the language ( the "en" from "[en-US-utf8]" )
78 while(!isSeparator(guess_str[current_pointer])){
79 lang+=guess_str[current_pointer];
80 current_pointer++;
82 current_pointer++;
84 //this is to pick up the country ( the "US" from "[en-US-utf8]" )
85 while(!isSeparator(guess_str[current_pointer])){
86 country+=guess_str[current_pointer];
87 current_pointer++;
89 current_pointer++;
91 //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
92 while(!isSeparator(guess_str[current_pointer])){
93 enc+=guess_str[current_pointer];
94 current_pointer++;
97 if(lang!=""){//if not we use the default value
98 language_str=lang;
100 country_str=country;
102 if(enc!=""){//if not we use the default value
103 encoding_str=enc;
108 Guess::~Guess()
112 bool Guess::operator==(const string& lang)
114 string toString;
115 toString += GetLanguage();
116 toString += "-";
117 toString += GetCountry();
118 toString += "-";
119 toString += GetEncoding();
120 return start(toString, lang);
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */