report changes from Curl backend
[platform/upstream/libzypp.git] / zypp / @Review / LangCode.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13    File:       LangCode.cc
14
15    Author:     Michael Andres <ma@suse.de>
16    Maintainer: Michael Andres <ma@suse.de>
17
18 /-*/
19
20 #include <iostream>
21
22 #include <y2util/LangCode.h>
23
24 using namespace std;
25
26 ///////////////////////////////////////////////////////////////////
27 //
28 //
29 //      METHOD NAME : LangCode::LangCode
30 //      METHOD TYPE : Constructor
31 //
32 LangCode::LangCode( const std::string & code_r )
33 {
34   string t;
35   string::size_type sep = code_r.find_first_of( "@." );
36   if ( sep == string::npos ) {
37     t = code_r;
38   } else {
39     t = code_r.substr( 0, sep );
40   }
41
42   sep = t.find( '_' );
43   if ( sep == string::npos ) {
44     _language = ISOLanguage( t );
45   } else {
46     _language = ISOLanguage( t.substr( 0, sep ) );
47     _country = ISOCountry( t.substr( sep+1 ) );
48   }
49
50 }
51
52 ///////////////////////////////////////////////////////////////////
53 //
54 //
55 //      METHOD NAME : LangCode::code
56 //      METHOD TYPE : std::string
57 //
58 std::string LangCode::code() const
59 {
60   string ret( languageCode() );
61   if ( hasCountry() )
62     ret += "_" + countryCode();
63   return ret;
64 }
65
66 ///////////////////////////////////////////////////////////////////
67 //
68 //
69 //      METHOD NAME : LangCode::name
70 //      METHOD TYPE : std::string
71 //
72 std::string LangCode::name() const
73 {
74   string ret( languageName() );
75   if ( hasCountry() )
76     ret += " (" + countryName() + ")";
77   return ret;
78 }
79
80 /******************************************************************
81 **
82 **
83 **      FUNCTION NAME : operator<<
84 **      FUNCTION TYPE : std::ostream &
85 */
86 std::ostream & operator<<( std::ostream & str, const LangCode & obj )
87 {
88   return str << obj.code();
89 }