Skip to content

Commit 2c7104d

Browse files
author
James McLaughlin
committed
Replace utf8proc with simpler string handling
1 parent 59fcca4 commit 2c7104d

File tree

6 files changed

+10
-14494
lines changed

6 files changed

+10
-14494
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project (json-builder)
44

55
set (CMAKE_C_FLAGS "-std=c89 -ansi -pedantic -Wall -I../json-parser ${CMAKE_C_FLAGS}")
66

7-
set (SOURCES ${SOURCES} json-builder.c utf8proc.c)
7+
set (SOURCES ${SOURCES} json-builder.c)
88

99
add_library (jsonbuilder ${SOURCES})
1010

LICENSE

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11

2-
All files with the exception of utf8proc.c, utf8proc.h and utf8proc_data.h
3-
----
4-
52
Copyright (C) 2014 James McLaughlin. All rights reserved.
63

74
Redistribution and use in source and binary forms, with or without
@@ -27,71 +24,3 @@ All files with the exception of utf8proc.c, utf8proc.h and utf8proc_data.h
2724
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2825
SUCH DAMAGE.
2926

30-
31-
utf8proc.c, utf8proc.h and utf8proc_data.h
32-
----
33-
34-
Copyright (c) 2009, 2013 Public Software Group e. V., Berlin, Germany
35-
36-
Permission is hereby granted, free of charge, to any person obtaining a
37-
copy of this software and associated documentation files (the "Software"),
38-
to deal in the Software without restriction, including without limitation
39-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
40-
and/or sell copies of the Software, and to permit persons to whom the
41-
Software is furnished to do so, subject to the following conditions:
42-
43-
The above copyright notice and this permission notice shall be included in
44-
all copies or substantial portions of the Software.
45-
46-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
51-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
52-
DEALINGS IN THE SOFTWARE.
53-
54-
55-
This software distribution contains derived data from a modified version of
56-
the Unicode data files. The following license applies to that data:
57-
58-
COPYRIGHT AND PERMISSION NOTICE
59-
60-
Copyright (c) 1991-2007 Unicode, Inc. All rights reserved. Distributed
61-
under the Terms of Use in http://www.unicode.org/copyright.html.
62-
63-
Permission is hereby granted, free of charge, to any person obtaining a
64-
copy of the Unicode data files and any associated documentation (the "Data
65-
Files") or Unicode software and any associated documentation (the
66-
"Software") to deal in the Data Files or Software without restriction,
67-
including without limitation the rights to use, copy, modify, merge,
68-
publish, distribute, and/or sell copies of the Data Files or Software, and
69-
to permit persons to whom the Data Files or Software are furnished to do
70-
so, provided that (a) the above copyright notice(s) and this permission
71-
notice appear with all copies of the Data Files or Software, (b) both the
72-
above copyright notice(s) and this permission notice appear in associated
73-
documentation, and (c) there is clear notice in each modified Data File or
74-
in the Software as well as in the documentation associated with the Data
75-
File(s) or Software that the data or software has been modified.
76-
77-
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
78-
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
79-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
80-
THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
81-
INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR
82-
CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
83-
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
84-
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
85-
PERFORMANCE OF THE DATA FILES OR SOFTWARE.
86-
87-
Except as contained in this notice, the name of a copyright holder shall
88-
not be used in advertising or otherwise to promote the sale, use or other
89-
dealings in these Data Files or Software without prior written
90-
authorization of the copyright holder.
91-
92-
93-
Unicode and the Unicode logo are trademarks of Unicode, Inc., and may be
94-
registered in some jurisdictions. All other trademarks and registered
95-
trademarks mentioned herein are the property of their respective owners.
96-
97-

json-builder.c

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#define snprintf _snprintf
4040
#endif
4141

42-
#include "utf8proc.h"
43-
4442
const static json_serialize_opts default_opts =
4543
{
4644
json_serialize_mode_single_line,
@@ -460,16 +458,12 @@ json_value * json_object_merge (json_value * objectA, json_value * objectB)
460458
static size_t measure_string (unsigned int length,
461459
const json_char * str)
462460
{
463-
ssize_t i = 0;
464-
int32_t c = -1;
461+
unsigned int i;
465462
size_t measured_length = 0;
466463

467-
for(;;)
464+
for(i = 0; i < length; ++ i)
468465
{
469-
i += utf8proc_iterate ((const uint8_t *) str + i, length - i, &c);
470-
471-
if(c == -1)
472-
break;
466+
json_char c = str [i];
473467

474468
switch (c)
475469
{
@@ -485,14 +479,9 @@ static size_t measure_string (unsigned int length,
485479
measured_length += 2;
486480
break;
487481

488-
case 0:
489-
490-
measured_length += 6;
491-
break;
492-
493482
default:
494483

495-
measured_length += utf8proc_measure_char (c);
484+
++ measured_length;
496485
break;
497486
};
498487
};
@@ -509,18 +498,12 @@ static size_t serialize_string (json_char * buf,
509498
unsigned int length,
510499
const json_char * str)
511500
{
512-
ssize_t i = 0;
513-
int32_t c = -1;
514-
json_char * orig_buf;
515-
516-
orig_buf = buf;
501+
json_char * orig_buf = buf;
502+
unsigned int i;
517503

518-
for(;;)
504+
for(i = 0; i < length; ++ i)
519505
{
520-
i += utf8proc_iterate ((const uint8_t *) str + i, length - i, &c);
521-
522-
if(c == -1)
523-
break;
506+
json_char c = str [i];
524507

525508
switch (c)
526509
{
@@ -533,17 +516,9 @@ static size_t serialize_string (json_char * buf,
533516
case '\r': PRINT_ESCAPED ('r'); continue;
534517
case '\t': PRINT_ESCAPED ('t'); continue;
535518

536-
case 0:
537-
538-
PRINT_ESCAPED ('u');
539-
sprintf (buf, "%04x", c);
540-
buf += 4;
541-
542-
break;
543-
544519
default:
545520

546-
buf += utf8proc_encode_char (c, (uint8_t *) buf);
521+
*buf ++ = c;
547522
break;
548523
};
549524
};

0 commit comments

Comments
 (0)