faml 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +0 -3
- data/Appraisals +5 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/ext/attribute_builder/attribute_builder.c +63 -31
- data/ext/attribute_builder/extconf.rb +12 -0
- data/faml.gemspec +1 -1
- data/gemfiles/rails_4.0.gemfile +1 -1
- data/gemfiles/rails_4.1.gemfile +1 -1
- data/gemfiles/rails_4.2.gemfile +1 -1
- data/gemfiles/rails_edge.gemfile +2 -1
- data/incompatibilities/README.md +1 -1
- data/incompatibilities/spec/render/attribute_spec.md +0 -0
- data/lib/faml.rb +4 -4
- data/lib/faml/cli.rb +1 -1
- data/lib/faml/compiler.rb +7 -7
- data/lib/faml/engine.rb +4 -4
- data/lib/faml/filter_compilers.rb +12 -12
- data/lib/faml/filter_compilers/base.rb +1 -1
- data/lib/faml/filter_compilers/cdata.rb +1 -1
- data/lib/faml/filter_compilers/coffee.rb +1 -1
- data/lib/faml/filter_compilers/css.rb +1 -1
- data/lib/faml/filter_compilers/escaped.rb +1 -1
- data/lib/faml/filter_compilers/javascript.rb +1 -1
- data/lib/faml/filter_compilers/markdown.rb +1 -1
- data/lib/faml/filter_compilers/plain.rb +1 -1
- data/lib/faml/filter_compilers/preserve.rb +1 -1
- data/lib/faml/filter_compilers/ruby.rb +1 -1
- data/lib/faml/filter_compilers/sass.rb +1 -1
- data/lib/faml/filter_compilers/scss.rb +1 -1
- data/lib/faml/filter_compilers/tilt_base.rb +1 -2
- data/lib/faml/rails_helpers.rb +1 -1
- data/lib/faml/railtie.rb +1 -1
- data/lib/faml/text_compiler.rb +2 -2
- data/lib/faml/tilt.rb +1 -1
- data/lib/faml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +13 -0
- data/vendor/houdini/.gitignore +3 -0
- data/vendor/houdini/COPYING +7 -0
- data/vendor/houdini/Makefile +79 -0
- data/vendor/houdini/README.md +59 -0
- data/vendor/houdini/buffer.c +249 -0
- data/vendor/houdini/buffer.h +113 -0
- data/vendor/houdini/houdini.h +46 -0
- data/vendor/houdini/houdini_href_e.c +115 -0
- data/vendor/houdini/houdini_html_e.c +90 -0
- data/vendor/houdini/houdini_html_u.c +122 -0
- data/vendor/houdini/houdini_js_e.c +90 -0
- data/vendor/houdini/houdini_js_u.c +60 -0
- data/vendor/houdini/houdini_uri_e.c +107 -0
- data/vendor/houdini/houdini_uri_u.c +68 -0
- data/vendor/houdini/houdini_xml_e.c +136 -0
- data/vendor/houdini/html_unescape.gperf +258 -0
- data/vendor/houdini/html_unescape.h +754 -0
- data/vendor/houdini/tools/build_table.py +13 -0
- data/vendor/houdini/tools/build_tables.c +51 -0
- data/vendor/houdini/tools/wikipedia_table.txt +2025 -0
- metadata +23 -3
data/lib/faml/rails_helpers.rb
CHANGED
data/lib/faml/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Faml
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer :faml do |app|
|
4
|
-
|
4
|
+
require_relative 'rails_handler'
|
5
5
|
ActionView::Template.register_template_handler(:haml, Faml::RailsHandler.new)
|
6
6
|
ActionView::Template.register_template_handler(:faml, Faml::RailsHandler.new)
|
7
7
|
end
|
data/lib/faml/text_compiler.rb
CHANGED
data/lib/faml/tilt.rb
CHANGED
data/lib/faml/version.rb
CHANGED
@@ -159,6 +159,19 @@ HAML
|
|
159
159
|
expect(render_string(<<HAML)).to eq("<span a='2' b='1'></span>\n")
|
160
160
|
%span{b: __LINE__,
|
161
161
|
a: __LINE__}
|
162
|
+
HAML
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'allows NUL characters' do
|
166
|
+
expect(render_string('%span{"foo\0bar" => "hello"}')).to eq("<span foo\0bar='hello'></span>\n")
|
167
|
+
expect(render_string(<<'HAML')).to eq("<span foo\0bar='hello'></span>\n")
|
168
|
+
- val = "hello"
|
169
|
+
%span{"foo\0bar" => val}
|
170
|
+
HAML
|
171
|
+
expect(render_string(<<'HAML')).to eq("<span foo\0bar='hello'></span>\n")
|
172
|
+
- key = "foo\0bar"
|
173
|
+
- val = "hello"
|
174
|
+
%span{key => val}
|
162
175
|
HAML
|
163
176
|
end
|
164
177
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2012 Vicent Martí
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# GNU Makefile
|
2
|
+
# Copyright (C) 2012 Przemyslaw Pawelczyk <przemoc@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
# copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included
|
13
|
+
# in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
16
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
SRCS := buffer.c houdini_href_e.c houdini_html_e.c houdini_html_u.c houdini_js_e.c houdini_js_u.c houdini_uri_e.c houdini_uri_u.c houdini_xml_e.c
|
24
|
+
OBJS := $(addsuffix .o,$(basename $(SRCS)))
|
25
|
+
DEPS := $(addsuffix .d,$(basename $(SRCS)))
|
26
|
+
NAME := houdini
|
27
|
+
|
28
|
+
SRCDIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
29
|
+
OBJDIR ?= ./
|
30
|
+
OBJS := $(addprefix $(OBJDIR),$(OBJS))
|
31
|
+
SLIB := lib$(NAME).a
|
32
|
+
|
33
|
+
vpath %.c $(SRCDIR)
|
34
|
+
vpath %.h $(SRCDIR)
|
35
|
+
|
36
|
+
AR ?= ar
|
37
|
+
CC ?= gcc
|
38
|
+
GPERF ?= gperf
|
39
|
+
SED ?= sed
|
40
|
+
|
41
|
+
CFLAGS ?= -O2
|
42
|
+
# -Wno-missing-field-initializers - gperf's header doesn't pass on -Wextra
|
43
|
+
MANDATORY_FLAGS := -Wall -Wextra -Wno-missing-field-initializers
|
44
|
+
override CFLAGS := $(MANDATORY_FLAGS) $(CFLAGS)
|
45
|
+
|
46
|
+
.PHONY: all clean objects package
|
47
|
+
|
48
|
+
all: package
|
49
|
+
|
50
|
+
objects: $(OBJS)
|
51
|
+
package: $(SLIB)
|
52
|
+
|
53
|
+
$(SLIB): $(OBJS)
|
54
|
+
$(AR) rcs $@ $^
|
55
|
+
|
56
|
+
$(OBJS): | $(OBJDIR)
|
57
|
+
|
58
|
+
$(OBJDIR):
|
59
|
+
mkdir -p $@
|
60
|
+
|
61
|
+
$(OBJDIR)%.o: %.c
|
62
|
+
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
|
63
|
+
|
64
|
+
%.d: %.c
|
65
|
+
@set -e; \
|
66
|
+
$(RM) $@; \
|
67
|
+
$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) $< >$@.tmp; \
|
68
|
+
$(SED) 's,\($*\)\.o[ :]*,$$(OBJDIR)\1.o $@: ,g' <$@.tmp >$@; \
|
69
|
+
$(RM) $@.tmp
|
70
|
+
|
71
|
+
html_unescape.h: html_unescape.gperf
|
72
|
+
$(GPERF) -t -N find_entity -H hash_entity -K entity -C -l --null-strings -m100 $< >$@
|
73
|
+
|
74
|
+
clean:
|
75
|
+
$(RM) $(SLIB) $(OBJS) $(DEPS)
|
76
|
+
|
77
|
+
ifneq ($(MAKECMDGOALS),clean)
|
78
|
+
-include $(DEPS)
|
79
|
+
endif
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Houdini - The Escapist
|
2
|
+
======================
|
3
|
+
|
4
|
+
Houdini doesn't quite qualify as a library. In fact, I didn't even bother
|
5
|
+
to write a Makefile (well, others did). It's zero-dependency and modular.
|
6
|
+
Just stick the files you need in your project. Or go with all of them
|
7
|
+
(e.g. via git submodule) and use the static library that is built by
|
8
|
+
default when GNU make is invoked. Now you can freely escape some shit.
|
9
|
+
|
10
|
+
Houdini is a simple API for escaping text for the web. And unescaping it.
|
11
|
+
But that kind of breaks the joke in the name so nevermind.
|
12
|
+
|
13
|
+
- HTML escaping follows the OWASP suggestion. All other entities are left
|
14
|
+
as-is.
|
15
|
+
|
16
|
+
& --> &
|
17
|
+
< --> <
|
18
|
+
> --> >
|
19
|
+
" --> "
|
20
|
+
' --> ' ' is not recommended
|
21
|
+
/ --> / forward slash is included as it helps end an HTML entity
|
22
|
+
|
23
|
+
- HTML unescaping is fully RFC-compliant. Yes, that's the 253 different entities
|
24
|
+
for you, and decimal/hex code point specifiers.
|
25
|
+
|
26
|
+
- URI escaping and unescaping is fully RFC-compliant.
|
27
|
+
|
28
|
+
- URL escaping and unescaping is the same as generic URIs,
|
29
|
+
but spaces are changed to `+`.
|
30
|
+
|
31
|
+
**WARNING:** Houdini parses **only** UTF-8 strings, and generates **only**
|
32
|
+
UTF-8 strings. If you are using another encoding, you should probably transcode
|
33
|
+
*before* passing the buffer to Houdini.
|
34
|
+
|
35
|
+
### Current API:
|
36
|
+
|
37
|
+
Do you really need docs for this?
|
38
|
+
|
39
|
+
~~~~ c
|
40
|
+
int houdini_escape_html(gh_buf *ob, const uint8_t *src, size_t size);
|
41
|
+
int houdini_escape_html0(gh_buf *ob, const uint8_t *src, size_t size, int secure);
|
42
|
+
int houdini_unescape_html(gh_buf *ob, const uint8_t *src, size_t size);
|
43
|
+
int houdini_escape_xml(gh_buf *ob, const uint8_t *src, size_t size);
|
44
|
+
int houdini_escape_uri(gh_buf *ob, const uint8_t *src, size_t size);
|
45
|
+
int houdini_escape_url(gh_buf *ob, const uint8_t *src, size_t size);
|
46
|
+
int houdini_escape_href(gh_buf *ob, const uint8_t *src, size_t size);
|
47
|
+
int houdini_unescape_uri(gh_buf *ob, const uint8_t *src, size_t size);
|
48
|
+
int houdini_unescape_url(gh_buf *ob, const uint8_t *src, size_t size);
|
49
|
+
int houdini_escape_js(gh_buf *ob, const uint8_t *src, size_t size);
|
50
|
+
int houdini_unescape_js(gh_buf *ob, const uint8_t *src, size_t size);
|
51
|
+
~~~~
|
52
|
+
|
53
|
+
Pass your string. It'll get escaped/unescaped in the target buffer, and the call will return 1.
|
54
|
+
If the given string has nothing to escape/unescape, the call will return 0 and the
|
55
|
+
output buffer will be empty.
|
56
|
+
|
57
|
+
### Questions?
|
58
|
+
|
59
|
+
Open an issue. Or shout angrily at me on Twitter ([@vmg](https://twitter.com/vmg)).
|
@@ -0,0 +1,249 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#include <stdarg.h>
|
8
|
+
#include <ctype.h>
|
9
|
+
#include <string.h>
|
10
|
+
#include <assert.h>
|
11
|
+
#include <string.h>
|
12
|
+
#include <stdio.h>
|
13
|
+
#include <stdlib.h>
|
14
|
+
#include <sys/param.h>
|
15
|
+
|
16
|
+
#include "buffer.h"
|
17
|
+
|
18
|
+
/* Used as default value for gh_buf->ptr so that people can always
|
19
|
+
* assume ptr is non-NULL and zero terminated even for new gh_bufs.
|
20
|
+
*/
|
21
|
+
char gh_buf__initbuf[1];
|
22
|
+
char gh_buf__oom[1];
|
23
|
+
|
24
|
+
#define ENSURE_SIZE(b, d) \
|
25
|
+
if ((d) > buf->asize && gh_buf_grow(b, (d)) < 0)\
|
26
|
+
return -1;
|
27
|
+
|
28
|
+
void gh_buf_init(gh_buf *buf, size_t initial_size)
|
29
|
+
{
|
30
|
+
buf->asize = 0;
|
31
|
+
buf->size = 0;
|
32
|
+
buf->ptr = gh_buf__initbuf;
|
33
|
+
|
34
|
+
if (initial_size)
|
35
|
+
gh_buf_grow(buf, initial_size);
|
36
|
+
}
|
37
|
+
|
38
|
+
int gh_buf_try_grow(gh_buf *buf, size_t target_size, bool mark_oom)
|
39
|
+
{
|
40
|
+
char *new_ptr;
|
41
|
+
size_t new_size;
|
42
|
+
|
43
|
+
if (buf->ptr == gh_buf__oom)
|
44
|
+
return -1;
|
45
|
+
|
46
|
+
if (target_size <= buf->asize)
|
47
|
+
return 0;
|
48
|
+
|
49
|
+
if (buf->asize == 0) {
|
50
|
+
new_size = target_size;
|
51
|
+
new_ptr = NULL;
|
52
|
+
} else {
|
53
|
+
new_size = buf->asize;
|
54
|
+
new_ptr = buf->ptr;
|
55
|
+
}
|
56
|
+
|
57
|
+
/* grow the buffer size by 1.5, until it's big enough
|
58
|
+
* to fit our target size */
|
59
|
+
while (new_size < target_size)
|
60
|
+
new_size = (new_size << 1) - (new_size >> 1);
|
61
|
+
|
62
|
+
/* round allocation up to multiple of 8 */
|
63
|
+
new_size = (new_size + 7) & ~7;
|
64
|
+
|
65
|
+
new_ptr = realloc(new_ptr, new_size);
|
66
|
+
|
67
|
+
if (!new_ptr) {
|
68
|
+
if (mark_oom)
|
69
|
+
buf->ptr = gh_buf__oom;
|
70
|
+
return -1;
|
71
|
+
}
|
72
|
+
|
73
|
+
buf->asize = new_size;
|
74
|
+
buf->ptr = new_ptr;
|
75
|
+
|
76
|
+
/* truncate the existing buffer size if necessary */
|
77
|
+
if (buf->size >= buf->asize)
|
78
|
+
buf->size = buf->asize - 1;
|
79
|
+
buf->ptr[buf->size] = '\0';
|
80
|
+
|
81
|
+
return 0;
|
82
|
+
}
|
83
|
+
|
84
|
+
void gh_buf_free(gh_buf *buf)
|
85
|
+
{
|
86
|
+
if (!buf) return;
|
87
|
+
|
88
|
+
if (buf->ptr != gh_buf__initbuf && buf->ptr != gh_buf__oom)
|
89
|
+
free(buf->ptr);
|
90
|
+
|
91
|
+
gh_buf_init(buf, 0);
|
92
|
+
}
|
93
|
+
|
94
|
+
void gh_buf_clear(gh_buf *buf)
|
95
|
+
{
|
96
|
+
buf->size = 0;
|
97
|
+
if (buf->asize > 0)
|
98
|
+
buf->ptr[0] = '\0';
|
99
|
+
}
|
100
|
+
|
101
|
+
int gh_buf_set(gh_buf *buf, const char *data, size_t len)
|
102
|
+
{
|
103
|
+
if (len == 0 || data == NULL) {
|
104
|
+
gh_buf_clear(buf);
|
105
|
+
} else {
|
106
|
+
if (data != buf->ptr) {
|
107
|
+
ENSURE_SIZE(buf, len + 1);
|
108
|
+
memmove(buf->ptr, data, len);
|
109
|
+
}
|
110
|
+
buf->size = len;
|
111
|
+
buf->ptr[buf->size] = '\0';
|
112
|
+
}
|
113
|
+
return 0;
|
114
|
+
}
|
115
|
+
|
116
|
+
int gh_buf_sets(gh_buf *buf, const char *string)
|
117
|
+
{
|
118
|
+
return gh_buf_set(buf, string, string ? strlen(string) : 0);
|
119
|
+
}
|
120
|
+
|
121
|
+
int gh_buf_putc(gh_buf *buf, char c)
|
122
|
+
{
|
123
|
+
ENSURE_SIZE(buf, buf->size + 2);
|
124
|
+
buf->ptr[buf->size++] = c;
|
125
|
+
buf->ptr[buf->size] = '\0';
|
126
|
+
return 0;
|
127
|
+
}
|
128
|
+
|
129
|
+
int gh_buf_put(gh_buf *buf, const void *data, size_t len)
|
130
|
+
{
|
131
|
+
ENSURE_SIZE(buf, buf->size + len + 1);
|
132
|
+
memmove(buf->ptr + buf->size, data, len);
|
133
|
+
buf->size += len;
|
134
|
+
buf->ptr[buf->size] = '\0';
|
135
|
+
return 0;
|
136
|
+
}
|
137
|
+
|
138
|
+
int gh_buf_puts(gh_buf *buf, const char *string)
|
139
|
+
{
|
140
|
+
assert(string);
|
141
|
+
return gh_buf_put(buf, string, strlen(string));
|
142
|
+
}
|
143
|
+
|
144
|
+
int gh_buf_vprintf(gh_buf *buf, const char *format, va_list ap)
|
145
|
+
{
|
146
|
+
int len;
|
147
|
+
const size_t expected_size = buf->size + (strlen(format) * 2);
|
148
|
+
|
149
|
+
ENSURE_SIZE(buf, expected_size);
|
150
|
+
|
151
|
+
while (1) {
|
152
|
+
va_list args;
|
153
|
+
va_copy(args, ap);
|
154
|
+
|
155
|
+
len = vsnprintf(
|
156
|
+
buf->ptr + buf->size,
|
157
|
+
buf->asize - buf->size,
|
158
|
+
format, args
|
159
|
+
);
|
160
|
+
|
161
|
+
if (len < 0) {
|
162
|
+
free(buf->ptr);
|
163
|
+
buf->ptr = gh_buf__oom;
|
164
|
+
return -1;
|
165
|
+
}
|
166
|
+
|
167
|
+
if ((size_t)len + 1 <= buf->asize - buf->size) {
|
168
|
+
buf->size += len;
|
169
|
+
break;
|
170
|
+
}
|
171
|
+
|
172
|
+
ENSURE_SIZE(buf, buf->size + len + 1);
|
173
|
+
}
|
174
|
+
|
175
|
+
return 0;
|
176
|
+
}
|
177
|
+
|
178
|
+
int gh_buf_printf(gh_buf *buf, const char *format, ...)
|
179
|
+
{
|
180
|
+
int r;
|
181
|
+
va_list ap;
|
182
|
+
|
183
|
+
va_start(ap, format);
|
184
|
+
r = gh_buf_vprintf(buf, format, ap);
|
185
|
+
va_end(ap);
|
186
|
+
|
187
|
+
return r;
|
188
|
+
}
|
189
|
+
|
190
|
+
void gh_buf_copy_cstr(char *data, size_t datasize, const gh_buf *buf)
|
191
|
+
{
|
192
|
+
size_t copylen;
|
193
|
+
|
194
|
+
assert(data && datasize && buf);
|
195
|
+
|
196
|
+
data[0] = '\0';
|
197
|
+
|
198
|
+
if (buf->size == 0 || buf->asize <= 0)
|
199
|
+
return;
|
200
|
+
|
201
|
+
copylen = buf->size;
|
202
|
+
if (copylen > datasize - 1)
|
203
|
+
copylen = datasize - 1;
|
204
|
+
memmove(data, buf->ptr, copylen);
|
205
|
+
data[copylen] = '\0';
|
206
|
+
}
|
207
|
+
|
208
|
+
void gh_buf_swap(gh_buf *buf_a, gh_buf *buf_b)
|
209
|
+
{
|
210
|
+
gh_buf t = *buf_a;
|
211
|
+
*buf_a = *buf_b;
|
212
|
+
*buf_b = t;
|
213
|
+
}
|
214
|
+
|
215
|
+
char *gh_buf_detach(gh_buf *buf)
|
216
|
+
{
|
217
|
+
char *data = buf->ptr;
|
218
|
+
|
219
|
+
if (buf->asize == 0 || buf->ptr == gh_buf__oom)
|
220
|
+
return NULL;
|
221
|
+
|
222
|
+
gh_buf_init(buf, 0);
|
223
|
+
|
224
|
+
return data;
|
225
|
+
}
|
226
|
+
|
227
|
+
void gh_buf_attach(gh_buf *buf, char *ptr, size_t asize)
|
228
|
+
{
|
229
|
+
gh_buf_free(buf);
|
230
|
+
|
231
|
+
if (ptr) {
|
232
|
+
buf->ptr = ptr;
|
233
|
+
buf->size = strlen(ptr);
|
234
|
+
if (asize)
|
235
|
+
buf->asize = (asize < buf->size) ? buf->size + 1 : asize;
|
236
|
+
else /* pass 0 to fall back on strlen + 1 */
|
237
|
+
buf->asize = buf->size + 1;
|
238
|
+
} else {
|
239
|
+
gh_buf_grow(buf, asize);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
int gh_buf_cmp(const gh_buf *a, const gh_buf *b)
|
244
|
+
{
|
245
|
+
int result = memcmp(a->ptr, b->ptr, MIN(a->size, b->size));
|
246
|
+
return (result != 0) ? result :
|
247
|
+
(a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
|
248
|
+
}
|
249
|
+
|