berns 4.1.2 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ #include <stdarg.h>
2
+
3
+ #include "strxcat.h"
4
+ #include "strxcpy.h"
5
+
6
+ char * strxcat(char *destination, size_t size, ...) {
7
+ va_list sources;
8
+ va_start(sources, size);
9
+
10
+ while(size > 1) {
11
+ char *source = va_arg(sources, char*);
12
+ size_t position = strxcpy(destination, source, size);
13
+ destination += position;
14
+ size -= position;
15
+ }
16
+
17
+ va_end(sources);
18
+
19
+ return destination;
20
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef STRXCAT_H
2
+ #define STRXCAT_H
3
+ #include <stddef.h>
4
+
5
+ /*
6
+ * Concatenate an arbitrary number of char* into a destination. Copies at most
7
+ * size characters into the destination.
8
+ */
9
+ extern char * strxcat(char *destination, size_t size, ...);
10
+
11
+ #endif
@@ -0,0 +1,50 @@
1
+ #include "strxcpy.h"
2
+
3
+ /* The below is simply OpenBSD's strlcpy function, renamed so it can be vendored. */
4
+
5
+ /* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */
6
+
7
+ /*
8
+ * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
9
+ *
10
+ * Permission to use, copy, modify, and distribute this software for any
11
+ * purpose with or without fee is hereby granted, provided that the above
12
+ * copyright notice and this permission notice appear in all copies.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
+ */
22
+
23
+ /*
24
+ * Copy string src to buffer dst of size dsize. At most dsize-1 chars will be
25
+ * copied. Always NUL terminates (unless dsize == 0). Returns strlen(src); if
26
+ * retval >= dsize, truncation occurred.
27
+ */
28
+ size_t strxcpy(char *dst, const char *src, size_t dsize) {
29
+ const char *osrc = src;
30
+ size_t nleft = dsize;
31
+
32
+ /* Copy as many bytes as will fit. */
33
+ if (nleft != 0) {
34
+ while (--nleft != 0) {
35
+ if ((*dst++ = *src++) == '\0') {
36
+ break;
37
+ }
38
+ }
39
+ }
40
+
41
+ /* Not enough room in dst, add NUL and traverse rest of src. */
42
+ if (nleft == 0) {
43
+ if (dsize != 0)
44
+ *dst = '\0'; /* NUL-terminate dst */
45
+ while (*src++)
46
+ ;
47
+ }
48
+
49
+ return(src - osrc - 1); /* count does not include NUL */
50
+ }
@@ -0,0 +1,32 @@
1
+ #ifndef STRXCPY_H
2
+ #define STRXCPY_H
3
+ #include <stddef.h>
4
+
5
+ /* The below is simply OpenBSD's strlcpy function, renamed so it can be vendored. */
6
+
7
+ /* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */
8
+
9
+ /*
10
+ * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
11
+ *
12
+ * Permission to use, copy, modify, and distribute this software for any
13
+ * purpose with or without fee is hereby granted, provided that the above
14
+ * copyright notice and this permission notice appear in all copies.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
17
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
19
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
+ */
24
+
25
+ /*
26
+ * Copy string src to buffer dst of size dsize. At most dsize-1 chars will be
27
+ * copied. Always NUL terminates (unless dsize == 0). Returns strlen(src); if
28
+ * retval >= dsize, truncation occurred.
29
+ */
30
+ extern size_t strxcpy(char *dst, const char *src, size_t dsize);
31
+
32
+ #endif
@@ -0,0 +1,9 @@
1
+ #import "strxempty.h"
2
+ #import "strxnew.h"
3
+
4
+ char * strxempty() {
5
+ char *str = strxnew(1);
6
+ str[0] = '\0';
7
+
8
+ return str;
9
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef STRXEMPTY_H
2
+ #define STRXEMPTY_H
3
+
4
+ /*
5
+ * Allocate an empty, NULL-terminated string.
6
+ */
7
+ extern char * strxempty();
8
+
9
+ #endif
@@ -0,0 +1,6 @@
1
+ #include "strxfree.h"
2
+ #include "ruby.h"
3
+
4
+ void strxfree(char * memory) {
5
+ return ruby_xfree(memory);
6
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef STRXFREE_H
2
+ #define STRXFREE_H
3
+
4
+ /*
5
+ * Frees a block of memory allocated by strxnew.
6
+ */
7
+ extern void strxfree(char * memory);
8
+
9
+ #endif
@@ -0,0 +1,8 @@
1
+ #include "ruby.h"
2
+ #include "strxnew.h"
3
+
4
+ char * strxnew(size_t size) {
5
+ char *string = ruby_xmalloc(size);
6
+
7
+ return string;
8
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef STRXNEW_H
2
+ #define STRXNEW_H
3
+ #include <stddef.h>
4
+
5
+ /*
6
+ * Allocates a new string using Ruby's ruby_xmalloc. Should be freed by
7
+ * strxfree.
8
+ */
9
+ extern char * strxnew(size_t size);
10
+
11
+ #endif
@@ -0,0 +1,6 @@
1
+ #include "ruby.h"
2
+ #include "strxresize.h"
3
+
4
+ char * strxresize(char * memory, size_t size) {
5
+ return ruby_xrealloc(memory, size);
6
+ }
@@ -0,0 +1,10 @@
1
+ #ifndef STRXRESIZE_H
2
+ #define STRXRESIZE_H
3
+ #include <stddef.h>
4
+
5
+ /*
6
+ * Resize a string allocated with strxnew.
7
+ */
8
+ char * strxresize(char * memory, size_t size);
9
+
10
+ #endif
Binary file
data/lib/berns/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Berns
3
- VERSION = '4.1.2'
3
+ VERSION = '4.3.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berns
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Beck
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-24 00:00:00.000000000 Z
12
+ date: 2023-05-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A utility library for generating HTML strings.
15
15
  email:
@@ -21,11 +21,23 @@ extensions:
21
21
  extra_rdoc_files: []
22
22
  files:
23
23
  - LICENSE.txt
24
- - README.org
24
+ - README.md
25
25
  - ext/berns/berns.c
26
26
  - ext/berns/extconf.rb
27
27
  - ext/berns/hescape.c
28
28
  - ext/berns/hescape.h
29
+ - ext/berns/strxcat.c
30
+ - ext/berns/strxcat.h
31
+ - ext/berns/strxcpy.c
32
+ - ext/berns/strxcpy.h
33
+ - ext/berns/strxempty.c
34
+ - ext/berns/strxempty.h
35
+ - ext/berns/strxfree.c
36
+ - ext/berns/strxfree.h
37
+ - ext/berns/strxnew.c
38
+ - ext/berns/strxnew.h
39
+ - ext/berns/strxresize.c
40
+ - ext/berns/strxresize.h
29
41
  - lib/berns.rb
30
42
  - lib/berns/berns.bundle
31
43
  - lib/berns/builder.rb
@@ -35,7 +47,7 @@ licenses:
35
47
  - MIT
36
48
  metadata:
37
49
  bug_tracker_uri: https://github.com/evanleck/berns/issues
38
- changelog_uri: https://github.com/evanleck/berns/blob/main/CHANGELOG.org
50
+ changelog_uri: https://github.com/evanleck/berns/blob/main/CHANGELOG.md
39
51
  homepage_uri: https://github.com/evanleck/berns
40
52
  rubygems_mfa_required: 'true'
41
53
  source_code_uri: https://github.com/evanleck/berns
@@ -54,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
66
  - !ruby/object:Gem::Version
55
67
  version: '2.0'
56
68
  requirements: []
57
- rubygems_version: 3.3.7
69
+ rubygems_version: 3.4.10
58
70
  signing_key:
59
71
  specification_version: 4
60
72
  summary: A utility library for generating HTML strings.