DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
file_extension.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_FILE_EXTENSION_H
13 #define DOCWIRE_FILE_EXTENSION_H
14 
15 #include <algorithm>
16 #include <compare>
17 #include <filesystem>
18 
19 namespace docwire
20 {
21 
28 {
29 public:
37  explicit file_extension(const std::string& ext) : m_ext(ext)
38  {
39  std::transform(m_ext.begin(), m_ext.end(), m_ext.begin(), [](char c) { return std::tolower(c); });
40  }
41 
49  explicit file_extension(const std::filesystem::path& p) : m_ext(p.extension().string())
50  {
51  std::transform(m_ext.begin(), m_ext.end(), m_ext.begin(), [](char c) { return std::tolower(c); });
52  }
53 
61  explicit file_extension(const char* ext) : m_ext(ext)
62  {
63  std::transform(m_ext.begin(), m_ext.end(), m_ext.begin(), [](char c) { return std::tolower(c); });
64  }
65 
66 
72  std::string string() const
73  {
74  return m_ext;
75  }
76 
84  bool operator==(const file_extension& other) const
85  {
86  return m_ext == other.m_ext;
87  }
88 
96  std::strong_ordering operator<=>(const file_extension& other) const
97  {
98  #ifdef __cpp_lib_three_way_comparison
99  return m_ext <=> other.m_ext;
100  #else
101  if (m_ext < other.m_ext)
102  return std::strong_ordering::less;
103  else if (m_ext > other.m_ext)
104  return std::strong_ordering::greater;
105  else
106  return std::strong_ordering::equal;
107  #endif
108  }
109 
110 private:
111  std::string m_ext;
112 };
113 
114 } // namespace docwire
115 
116 #endif
A class representing a file extension.
file_extension(const std::string &ext)
Constructs a file_extension object from a string.
std::strong_ordering operator<=>(const file_extension &other) const
Compares two file extensions for equality, ignoring case.
bool operator==(const file_extension &other) const
Compares two file extensions for equality, ignoring case.
file_extension(const std::filesystem::path &p)
Constructs a file_extension object from a path.
std::string string() const
Returns the file extension as a string.
file_extension(const char *ext)
Constructs a file_extension object from a const literal.
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19