Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Charset.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Characters_Charset_h_
5#define _Stroika_Foundation_Characters_Charset_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <memory>
10#include <string>
11
12/**
13 * \file
14 *
15 */
16
18
19 using namespace std;
20
21 class String;
22
23 /**
24 * This is NOT a widely used concept any longer. Its largely been replaced by UNICODE.
25 * But - it IS used in HTTP, and MIME, so its pretty important to continue supporting.
26 * https://www.w3.org/International/articles/http-charset/index#charset
27 *
28 * Information tagged with a Charset is used to select a CodeCvt object, which maps (typically from)
29 * that character set to UNICODE.
30 *
31 * See https://www.iana.org/assignments/character-sets/character-sets.xhtml
32 *
33 * \note - despite the name sounding similar to 'character set' - its really more of a combination
34 * of character set and character encoding.
35 *
36 * \note charset names are intrinsically compared case insensitively (@todo find reference for this but empirically its clear).
37 */
38 class Charset {
39 public:
40 /**
41 */
42 Charset (const Charset&) = default;
43 Charset (const std::string& charsetName);
44 Charset (const std::string_view& charsetName);
45 Charset (const String& charsetName);
46
47 public:
48 nonvirtual operator String () const;
49
50 public:
51 nonvirtual string AsNarrowSDKString () const;
52
53 public:
54 nonvirtual strong_ordering operator<=> (const Charset& rhs) const;
55 nonvirtual bool operator== (const Charset& rhs) const;
56
57 private:
58 struct Rep_;
59 shared_ptr<Rep_> fRep_;
60 };
61
62 /**
63 * See https://www.iana.org/assignments/character-sets/character-sets.xhtml
64 */
65 namespace WellKnownCharsets {
66
67 /**
68 */
69 static inline const Charset kUS_ASCII{"US-ASCII"sv};
70
71 /**
72 * HTTP 1.1 says that the default charset is ISO-8859-1.
73 */
74 static inline const Charset kISO_8859_1{"ISO-8859-1"sv};
75
76 /**
77 */
78 static inline const Charset kISO_Latin1{kISO_8859_1};
79
80 /**
81 */
82 static inline const Charset kUTF8{"UTF-8"sv};
83
84 }
85
86}
87
88/*
89 ********************************************************************************
90 ***************************** Implementation Details ***************************
91 ********************************************************************************
92 */
93#include "Charset.inl"
94
95#endif /*_Stroika_Foundation_Characters_Charset_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
STL namespace.