File: sutf.h

package info (click to toggle)
simdutf 7.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,244 kB
  • sloc: cpp: 60,074; ansic: 14,226; python: 3,364; sh: 321; makefile: 12
file content (40 lines) | stat: -rw-r--r-- 1,164 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "simdutf.h"

#if !defined(ICONV_AVAILABLE) && __has_include(<iconv.h>)
  #define ICONV_AVAILABLE 1
#endif //__has_include (<iconv.h>)
#if ICONV_AVAILABLE
  #include <iconv.h>
#endif

#include <filesystem>
#include <array>
#include <memory>
#include <queue>

constexpr size_t CHUNK_SIZE = 65536; // Must be at least 4

class CommandLine {
public:
  std::string from_encoding;
  std::string to_encoding;
  std::queue<std::filesystem::path> input_files;
  std::FILE *current_file{NULL};
  std::filesystem::path output_file;
  std::array<uint8_t, CHUNK_SIZE> input_data;
  std::array<char, CHUNK_SIZE * sizeof(uint32_t)> output_buffer;

  CommandLine() = default;
  static CommandLine parse_and_validate_arguments(int argc, char *argv[]);
  static void show_help();
  static void show_usage();
  static void show_formats();

  void run();
  void run_procedure(std::FILE *fp);
  template <typename PROCEDURE> void run_simdutf_procedure(PROCEDURE proc);
  void iconv_fallback(std::FILE *fp);
  bool load_chunk(size_t *input_size);
  bool write_to_file_descriptor(std::FILE *fp, const char *data, size_t length);
  size_t find_last_leading_byte(size_t size);
};