1 /***************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: guess.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_lingucomponent.hxx"
37 #include <libtextcat/textcat.h>
38 #include <altstrfunc.hxx>
45 language_str
= DEFAULT_LANGUAGE
;
46 country_str
= DEFAULT_COUNTRY
;
47 encoding_str
= DEFAULT_ENCODING
;
51 * this use a char * string to build the guess object
52 * a string like those is made as : [language-country-encoding]...
56 Guess::Guess(char * guess_str
)
64 //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
65 // if(strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_UNKOWN, strlen(_TEXTCAT_RESULT_UNKOWN)) != 0
67 // strncmp((const char*)(guess_str + 1), _TEXTCAT_RESULT_SHORT, strlen(_TEXTCAT_RESULT_SHORT)) != 0)
69 if(strcmp((const char*)(guess_str
+ 1), _TEXTCAT_RESULT_UNKOWN
) != 0
71 strcmp((const char*)(guess_str
+ 1), _TEXTCAT_RESULT_SHORT
) != 0)
74 int current_pointer
= 0;
76 //this is to go to the first char of the guess string ( the '[' of "[en-US-utf8]" )
77 while(!isSeparator(guess_str
[current_pointer
])){
82 //this is to pick up the language ( the "en" from "[en-US-utf8]" )
83 while(!isSeparator(guess_str
[current_pointer
])){
84 lang
+=guess_str
[current_pointer
];
89 //this is to pick up the country ( the "US" from "[en-US-utf8]" )
90 while(!isSeparator(guess_str
[current_pointer
])){
91 country
+=guess_str
[current_pointer
];
96 //this is to pick up the encoding ( the "utf8" from "[en-US-utf8]" )
97 while(!isSeparator(guess_str
[current_pointer
])){
98 enc
+=guess_str
[current_pointer
];
102 if(lang
!=""){//if not we use the default value
107 if(enc
!=""){//if not we use the default value
115 string
Guess::GetLanguage()
120 string
Guess::GetCountry()
125 string
Guess::GetEncoding()
130 bool Guess::operator==(string lang
)
133 toString
+= GetLanguage();
135 toString
+= GetCountry();
137 toString
+= GetEncoding();
138 return start(toString
, lang
);