include/relpipe/common/text/Iconv.h
author František Kučera <franta-hg@frantovo.cz>
Fri, 13 Dec 2019 14:55:06 +0100
branchv_0
changeset 20 a8ccd2b19faa
parent 18 9d566568d37c
permissions -rw-r--r--
types namespace
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes (library)
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the:
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 *  - GNU Lesser General Public License as published by the Free Software Foundation;
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *    version 3 of the License or (at your option)
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *  - GNU General Public License as published by the Free Software Foundation;
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 *    version 2 of the License.
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 *
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful,
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * GNU General Public License for more details.
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 *
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
 */
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#pragma once
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <string.h>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <iconv.h>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <string>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <array>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <assert.h>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <ostream>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include <sstream>
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
20
a8ccd2b19faa types namespace
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    30
#include "../type/typedefs.h"
a8ccd2b19faa types namespace
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    31
18
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
namespace relpipe {
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
namespace common {
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
namespace text {
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
/**
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
 * Iconv class is a simple wrapper for iconv() functions.
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
 * It converts text from one encoding to another.
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
 * 
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
 * List of all encodings: iconv --list
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
 * 
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
 * n.b. if the default (platform) encoding "" is used, it is required to initialize locales: setlocale(LC_ALL, "");
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
 */
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
class Iconv {
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
private:
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	class IconvInternal;
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	IconvInternal* internal;
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
public:
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	Iconv(std::string to, std::string from);
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	Iconv(std::string to, std::string from, size_t bufferSize);
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	virtual ~Iconv();
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	std::string convert(std::string originalText);
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
};
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
}
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
}
9d566568d37c Iconv and TextCodec classes for converting text encodings
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
}