include/relpipe/common/text/TextCodec.h
branchv_0
changeset 18 9d566568d37c
child 20 a8ccd2b19faa
equal deleted inserted replaced
17:46151cd23815 18:9d566568d37c
       
     1 /**
       
     2  * Relational pipes (library)
       
     3  * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the:
       
     7  *  - GNU Lesser General Public License as published by the Free Software Foundation;
       
     8  *    version 3 of the License or (at your option)
       
     9  *  - GNU General Public License as published by the Free Software Foundation;
       
    10  *    version 2 of the License.
       
    11  *
       
    12  * This program is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    15  * GNU General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License
       
    18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    19  */
       
    20 #pragma once
       
    21 
       
    22 #include <memory>
       
    23 
       
    24 #include "Iconv.h"
       
    25 
       
    26 namespace relpipe {
       
    27 namespace common {
       
    28 namespace text {
       
    29 
       
    30 /**
       
    31  * TextCodec converts text from an encoding (usually the plarform default) 
       
    32  * to our internal string representations (which is octet string consisting of UTF-8 encoded text).
       
    33  * 
       
    34  * bytes = platform encoding
       
    35  * text = our encoding
       
    36  * 
       
    37  * n.b. if the default (platform) encoding "" is used, it is required to initialize locales: setlocale(LC_ALL, "");
       
    38  */
       
    39 class TextCodec {
       
    40 private:
       
    41 	class TextCodecInternal;
       
    42 	TextCodecInternal* internal;
       
    43 public:
       
    44 	TextCodec();
       
    45 	TextCodec(const std::string& encoding);
       
    46 	virtual ~TextCodec();
       
    47 	std::string fromBytes(std::string bytes);
       
    48 	std::string toBytes(std::string text);
       
    49 };
       
    50 
       
    51 }
       
    52 }
       
    53 }