Skip to content

Commit e579c3b

Browse files
committed
Continue refactoring, renaming and add more tests. 2 Introduction for statefull io pump and funnel interfaces e.g. abstraction for doing internal data modification before input and output like encryption or compression, or data classification like detecting character set for test streams
1 parent c86fa85 commit e579c3b

File tree

152 files changed

+884
-652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+884
-652
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ Makefile
3030
**.tcl
3131
**.cmake
3232
**/**/result.txt
33-
33+
/test/test.xml

examples/cat_ext/main.cpp

Lines changed: 83 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include <vector>
1818

19-
#include <io/core/console.hpp>
2019
#include <io/core/files.hpp>
20+
#include <io/console/console.hpp>
2121

2222
#include <io/textapi/charset_detector.hpp>
2323
#include <io/textapi/charset_converter.hpp>
@@ -27,47 +27,47 @@ void file_to_console(std::error_code& ec,io::file&& f, io::console_out_writer& o
2727

2828
int main(int argc, const char** argv)
2929
{
30-
int ret = ERROR_SUCCESS;
31-
32-
io::console cons;
33-
io::console_error_stream cerr(cons);
34-
35-
io::console_out_writer out(cons);
36-
37-
if(argc < 2) {
38-
cerr << io::cclr::light_red << "No files to display." << io::cclr::reset << std::endl << std::endl;
39-
cerr << "\tCommand usage : ";
40-
cerr << io::cclr::navy_green << "cat_ext " << io::cclr::reset;
41-
cerr << '[' << io::cclr::magenta << "file..." << io::cclr::reset << ']' << std::endl;
42-
ret = EINVAL;
43-
}
44-
45-
std::error_code ec;
46-
for(std::size_t i =1; i < static_cast<std::size_t>(argc); i++) {
47-
io::file src_file(argv[i]);
48-
if( !src_file.exist() ) {
49-
ret = ENOENT;
50-
print_error(cerr,"Requested",argv[i],"not found");
51-
break;
52-
}
53-
file_to_console(ec,std::move(src_file), out);
54-
if(ec) {
55-
ret = ec.value();
56-
print_error(cerr,"Issue with" ,argv[i], ec.message().data() );
57-
break;
58-
}
59-
}
60-
61-
return ret;
30+
int ret = ERROR_SUCCESS;
31+
32+
io::console cons;
33+
io::console_error_stream cerr(cons);
34+
35+
io::console_out_writer out(cons);
36+
37+
if(argc < 2) {
38+
cerr << io::cclr::light_red << "No files to display." << io::cclr::reset << std::endl << std::endl;
39+
cerr << "\tCommand usage : ";
40+
cerr << io::cclr::navy_green << "cat_ext " << io::cclr::reset;
41+
cerr << '[' << io::cclr::magenta << "file..." << io::cclr::reset << ']' << std::endl;
42+
ret = EINVAL;
43+
}
44+
45+
std::error_code ec;
46+
for(std::size_t i =1; i < static_cast<std::size_t>(argc); i++) {
47+
io::file src_file(argv[i]);
48+
if( !src_file.exist() ) {
49+
ret = ENOENT;
50+
print_error(cerr,"Requested",argv[i],"not found");
51+
break;
52+
}
53+
file_to_console(ec,std::move(src_file), out);
54+
if(ec) {
55+
ret = ec.value();
56+
print_error(cerr,"Issue with",argv[i], ec.message().data() );
57+
break;
58+
}
59+
}
60+
61+
return ret;
6262
}
6363

6464

6565
void print_error(io::console_error_stream& err,const char* reason, const char* f, const char* what)
6666
{
67-
err << io::cclr::light_red << "Error" << io::cclr::reset << ": ";
68-
err << reason << " file ";
69-
err << io::cclr::yellow << f << io::cclr::reset;
70-
err << ' ' << what << io::cclr::reset << std::endl;
67+
err << io::cclr::light_red << "Error" << io::cclr::reset << ": ";
68+
err << reason << " file ";
69+
err << io::cclr::yellow << f << io::cclr::reset;
70+
err << ' ' << what << io::cclr::reset << std::endl;
7171
}
7272

7373
#ifdef __IO_WINDOWS_BACKEND__
@@ -76,42 +76,52 @@ static const char* WENDL = "\r\n";
7676
static const char* WENDL = "\n";
7777
#endif // __IO_WINDOWS_BACKEND__
7878

79+
80+
io::s_pump data_pump_for_charset(std::error_code& ec,const io::s_read_channel& rch, const io::charset* chst, io::byte_buffer&& buff)
81+
{
82+
io::s_pump ret;
83+
if(io::code_pages::utf8() == chst)
84+
ret = io::buffered_channel_pump::create(ec, rch, std::forward<io::byte_buffer>(buff) );
85+
else
86+
ret = io::charset_converting_channel_pump::create(ec, rch, chst, io::code_pages::utf8(), std::forward<io::byte_buffer>(buff) );
87+
return ret;
88+
}
89+
7990
void file_to_console(std::error_code& ec,io::file&& f, io::console_out_writer& out)
8091
{
81-
io::s_read_channel rch = f.open_for_read(ec);
82-
if(!ec) {
83-
io::s_charset_detector chdet = io::charset_detector::create(ec);
84-
if(!ec) {
85-
// detect character set
86-
uint8_t buff[1024] = {0};
87-
std::size_t read = rch->read(ec, buff, 1024);
88-
if ( !ec && read > 0 ) {
89-
auto detect_status = chdet->detect( ec, buff, read );
90-
if(!ec && !detect_status) {
91-
ec = std::make_error_code(std::errc::illegal_byte_sequence);
92-
}
93-
else {
94-
out.write("Detected : ");
95-
out.write(detect_status.character_set()->name());
96-
out.write(WENDL);
97-
if( io::code_pages::utf8()->code() != detect_status.character_set()->code() ) {
98-
99-
}
100-
else {
101-
const char* it = reinterpret_cast<const char*>(buff);
102-
if( io::utf8_bom::is(it) ) {
103-
it += io::utf8_bom::len();
104-
read -= io::utf8_bom::len();
105-
}
106-
do {
107-
out.write(it, read);
108-
out.flush();
109-
read = rch->read(ec, buff, 1024 );
110-
it = reinterpret_cast<const char*>(buff);
111-
} while( read && !ec);
112-
}
113-
}
114-
}
115-
}
116-
}
92+
io::s_read_channel rch = f.open_for_read(ec);
93+
if(!ec) {
94+
// detect character set
95+
io::byte_buffer buff = io::byte_buffer::allocate(ec, 1024);
96+
if(!ec) {
97+
std::size_t read = rch->read(ec, const_cast<uint8_t*>(buff.position().get()), buff.capacity());
98+
if(!ec && read > 0 ) {
99+
io::s_charset_detector chdet = io::charset_detector::create(ec);
100+
buff.move(read);
101+
buff.flip();
102+
auto detect_status = chdet->detect( ec, buff.position().get(), read );
103+
if(!ec) {
104+
if(!detect_status) {
105+
ec = std::make_error_code(std::errc::illegal_byte_sequence);
106+
}
107+
else {
108+
out.write("Detected : ");
109+
out.write(detect_status.character_set()->name());
110+
out.write(WENDL);
111+
io::s_pump pmp = data_pump_for_charset(ec, rch, detect_status.character_set(), std::move(buff) );
112+
if(!ec) {
113+
io::reader in( std::move(pmp) );
114+
char tmp[1024] = {'\0'};
115+
std::size_t read = 0;
116+
do {
117+
read = in.read(ec, tmp, 1024);
118+
if(read > 0 && !ec)
119+
out.write(tmp, read);
120+
} while(read > 0 && !ec);
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
117127
}

examples/xml_event_parsing/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// For parsing event from
1212
#include <io/core/files.hpp>
13-
#include <io/core/console.hpp>
13+
#include <io/console/console.hpp>
1414
#include <io/core/char_cast.hpp>
1515

1616
#include <io/xml/event_stream_parser.hpp>

libio/include/io/config/compiler/clang.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# define __HAS_CPP_20 1
3131
#endif // C++ 20
3232
33-
#if __cplusplus >= 202302L
33+
#if __cplusplus >= 202502L
3434
# define __HAS_CPP_23 1
3535
#endif // C++ 23
3636
@@ -108,9 +108,11 @@
108108
#endif
109109
110110
#if __has_builtin(__builtin_bzero)
111-
# define io_zerro_mem(__p,__bytes) __builtin_bzero( (__p), (__bytes) )
111+
# define io_bzero(__p,__bytes) __builtin_bzero( (__p), (__bytes) )
112+
#elif __has_builtin(__builtin_memset)
113+
# define io_bzero(__p,__bytes) __builtin_memset( (__p), 0, (__bytes) )
112114
#else
113-
# define io_zerro_mem(__p,__bytes) io_memset( (__p), 0, (__bytes) )
115+
# define io_bzero(__p,__bytes) std::memset( (__p), 0, (__bytes) )
114116
#endif
115117
116118
#if __has_builtin(__builtin_memchr)

libio/include/io/config/compiler/gcc.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2016-2023
3+
* Copyright (c) 2016-2025
44
* Viktor Gubin
55
*
66
* Use, modification and distribution are subject to the
@@ -34,6 +34,10 @@
3434
# define __HAS_CPP_23 1
3535
#endif // C++ 23
3636
37+
#if __cplusplus >= 202302L
38+
# define __HAS_CPP_26 1
39+
#endif // C++ 26
40+
3741
#define HAS_PRAGMA_ONCE
3842
3943
#include <cstddef>
@@ -93,7 +97,7 @@
9397
9498
#define io_memcmp(__p1,__p2,__bytes) __builtin_memcmp((__p1),(__p2),(__bytes))
9599
96-
#define io_zerro_mem(__p,__bytes) __builtin_bzero( (__p), (__bytes) )
100+
#define io_bzero(__p,__bytes) __builtin_bzero( (__p), (__bytes) )
97101
98102
#define io_memchr(__s,__c,__n) __builtin_memchr((__s),(__c),(__n))
99103

libio/include/io/config/compiler/ms_visual_cpp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ typedef SSIZE_T ssize_t;
124124

125125
#define io_memcmp(__p1,__p2,__bytes) memcmp( (__p1), (__p2),(__bytes) )
126126

127-
#define io_zerro_mem(__p,__bytes) RtlZeroMemory( (__p), (__bytes) )
127+
#define io_bzero(__p,__bytes) RtlZeroMemory( (__p), (__bytes) )
128128

129129
#define io_strcat(__dst,__src) strcat( (__dst) , (__src) )
130130

libio/include/io/config/libio_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2016-2023
3+
* Copyright (c) 2016-2025
44
* Viktor Gubin
55
*
66
* Use, modification and distribution are subject to the

libio/include/io/config/libs/exceptions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2016-2023
3+
* Copyright (c) 2016-2025
44
* Viktor Gubin
55
*
66
* Use, modification and distribution are subject to the

libio/include/io/config/libs/h_allocator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2016-2023
3+
* Copyright (c) 2016-2025
44
* Viktor Gubin
55
*
66
* Use, modification and distribution are subject to the

libio/include/io/config/libs/intrusive_ptr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2016-2023
3+
* Copyright (c) 2016-2025
44
* Viktor Gubin
55
*
66
* Use, modification and distribution are subject to the

0 commit comments

Comments
 (0)