ruxml 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/ruxml/array.cpp +71 -0
- data/ext/ruxml/array.hpp +35 -0
- data/ext/ruxml/extconf.rb +5 -0
- data/ext/ruxml/memory.cpp +222 -0
- data/ext/ruxml/memory.hpp +112 -0
- data/ext/ruxml/parser.cpp +490 -0
- data/ext/ruxml/parser.hpp +140 -0
- data/ext/ruxml/ruxml.cpp +273 -0
- data/ext/ruxml/str.cpp +216 -0
- data/ext/ruxml/str.hpp +111 -0
- data/lib/ruxml.rb +6 -0
- data/lib/ruxml/parse_error.rb +9 -0
- data/lib/ruxml/parser.rb +25 -0
- data/lib/ruxml/version.rb +3 -0
- metadata +100 -0
data/ext/ruxml/str.hpp
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <cstdint>
|
4
|
+
#include <cstring>
|
5
|
+
|
6
|
+
#include "memory.hpp"
|
7
|
+
|
8
|
+
size_t zstr_length(const char *str);
|
9
|
+
char *zstr_dup(const char *str);
|
10
|
+
char *zstr_dup(const char *str, int64_t size);
|
11
|
+
int zstr_find_last(const char *str, char c);
|
12
|
+
|
13
|
+
struct String {
|
14
|
+
int32_t length;
|
15
|
+
char *data;
|
16
|
+
};
|
17
|
+
|
18
|
+
inline String operator "" _str(const char *data, size_t length) {
|
19
|
+
return String{static_cast<int32_t>(length),
|
20
|
+
const_cast<char *>(data)};
|
21
|
+
}
|
22
|
+
|
23
|
+
inline String copy_string(MemoryArena *arena, uint32_t length, char *input) {
|
24
|
+
uint32_t buf_length = length + 1;
|
25
|
+
|
26
|
+
String str;
|
27
|
+
str.length = length;
|
28
|
+
str.data = (char *) allocate_size(arena, buf_length);
|
29
|
+
memcpy(str.data, input, length);
|
30
|
+
str.data[length] = 0;
|
31
|
+
return str;
|
32
|
+
}
|
33
|
+
|
34
|
+
inline String copy_string(MemoryArena *arena, String input) {
|
35
|
+
return copy_string(arena, input.length, input.data);
|
36
|
+
}
|
37
|
+
|
38
|
+
inline String copy_zstring(MemoryArena *arena, char *input) {
|
39
|
+
return copy_string(arena, strlen(input), input);
|
40
|
+
}
|
41
|
+
|
42
|
+
inline String as_zstring(char *input) {
|
43
|
+
String str;
|
44
|
+
str.length = static_cast<int32_t>(zstr_length(input));
|
45
|
+
str.data = input;
|
46
|
+
return str;
|
47
|
+
}
|
48
|
+
|
49
|
+
inline String str_from_index(String s, int index) {
|
50
|
+
return String{s.length - index, s.data + index};
|
51
|
+
}
|
52
|
+
|
53
|
+
inline String str_until_index(String s, int index) {
|
54
|
+
return String{index + 1, s.data};
|
55
|
+
}
|
56
|
+
|
57
|
+
inline String str_after_index(String s, int index) {
|
58
|
+
return String{s.length - index - 1, s.data + index + 1};
|
59
|
+
}
|
60
|
+
|
61
|
+
inline String str_before_index(String s, int index) {
|
62
|
+
return String{index, s.data};
|
63
|
+
}
|
64
|
+
|
65
|
+
inline String str_between(String s, int after_index, int before_index) {
|
66
|
+
return String{before_index - after_index - 1, s.data + after_index + 1};
|
67
|
+
}
|
68
|
+
|
69
|
+
inline String str_empty() {
|
70
|
+
return String{0, nullptr};
|
71
|
+
}
|
72
|
+
|
73
|
+
bool parse_int(String string, int32_t *result_ptr);
|
74
|
+
|
75
|
+
inline int32_t parse_int_default(String string, int32_t default_value) {
|
76
|
+
int32_t result;
|
77
|
+
if (!parse_int(string, &result)) result = default_value;
|
78
|
+
return result;
|
79
|
+
}
|
80
|
+
|
81
|
+
bool parse_int64(String string, int64_t *result_ptr);
|
82
|
+
|
83
|
+
inline int64_t parse_int64_default(String string, int64_t default_value) {
|
84
|
+
int64_t result;
|
85
|
+
if (!parse_int64(string, &result)) result = default_value;
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
|
89
|
+
// Use in printf with format specifier %.*s
|
90
|
+
#define str_prt(s) s.length, s.data
|
91
|
+
|
92
|
+
String str_dup(String str);
|
93
|
+
String str_dup(const char *str);
|
94
|
+
String str_dup(const char *str, int length);
|
95
|
+
String str_dup(Allocator *allocator, String str);
|
96
|
+
String str_dup(Allocator *allocator, const char *str);
|
97
|
+
String str_dup(Allocator *allocator, const char *str, int length);
|
98
|
+
|
99
|
+
char* str_to_zstr(String str);
|
100
|
+
char* str_to_zstr(Allocator *allocator, String str);
|
101
|
+
|
102
|
+
String str_print(const char *fmt, ...);
|
103
|
+
String str_print(Allocator *allocator, const char *fmt, ...);
|
104
|
+
|
105
|
+
int str_find_last(String s, char c, int after = 0);
|
106
|
+
int str_find_first(String s, char c, int after = 0);
|
107
|
+
int str_compare(String a, String b);
|
108
|
+
bool str_equal(String a, String b);
|
109
|
+
bool str_equal(String a, const char *b);
|
110
|
+
bool str_equal(String a, const char *b_data, int b_length);
|
111
|
+
bool str_empty(String s);
|
data/lib/ruxml.rb
ADDED
data/lib/ruxml/parser.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module RUXML
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
def get_node
|
5
|
+
next_node
|
6
|
+
raise ParseError.new("RUXML encountered an error in the XML") if errored
|
7
|
+
node
|
8
|
+
end
|
9
|
+
|
10
|
+
def each
|
11
|
+
while next_node
|
12
|
+
yield node
|
13
|
+
end
|
14
|
+
raise ParseError.new("RUXML encountered an error in the XML") if errored
|
15
|
+
end
|
16
|
+
|
17
|
+
def each_node
|
18
|
+
while next_node
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
raise ParseError.new("RUXML encountered an error in the XML") if errored
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruxml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Divan Burger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.9.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.9.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.3
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- divan.burger@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/ruxml/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ext/ruxml/array.cpp
|
64
|
+
- ext/ruxml/array.hpp
|
65
|
+
- ext/ruxml/extconf.rb
|
66
|
+
- ext/ruxml/memory.cpp
|
67
|
+
- ext/ruxml/memory.hpp
|
68
|
+
- ext/ruxml/parser.cpp
|
69
|
+
- ext/ruxml/parser.hpp
|
70
|
+
- ext/ruxml/ruxml.cpp
|
71
|
+
- ext/ruxml/str.cpp
|
72
|
+
- ext/ruxml/str.hpp
|
73
|
+
- lib/ruxml.rb
|
74
|
+
- lib/ruxml/parse_error.rb
|
75
|
+
- lib/ruxml/parser.rb
|
76
|
+
- lib/ruxml/version.rb
|
77
|
+
homepage: https://www.github.com/divanburger/ruxml
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Simple fast XML parser
|
100
|
+
test_files: []
|