#include <assert.h>
#include <stdlib.h>
#include "Array.h"
#include "Boole.h"
#include "Dictionary.h"
#include "JSONPath.h"
#include "Number.h"
#include "Regexp.h"
#include "String.h"
Go to the source code of this file.
◆ _Class
◆ _JSONPath()
| Class * _JSONPath |
( |
void |
| ) |
|
Definition at line 118 of file JSONPath.c.
118 {
121
124 .name = "JSONPath",
127 .interfaceOffset = offsetof(
JSONPath, interface),
128 .interfaceSize = sizeof(JSONPathInterface),
131 });
132 });
133
134 return clazz;
135}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
static void destroy(Class *clazz)
static void initialize(Class *clazz)
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
A minimal JSONPath implementation.
◆ destroy()
| static void destroy |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::destroy(Class *)
Definition at line 99 of file JSONPath.c.
99 {
100
102}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
◆ initialize()
| static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 107 of file JSONPath.c.
107 {
108
110
111 _re =
re(
"(.[^.\\[]+|\\[[0-9]+\\])", 0);
112}
static ident objectForKeyPath(const ident root, const char *path)
Regexp * re(const char *pattern, int options)
ident interface
The interface of the Class.
◆ objectForKeyPath()
| static ident objectForKeyPath |
( |
const ident |
root, |
|
|
const char * |
path |
|
) |
| |
|
static |
Definition at line 45 of file JSONPath.c.
45 {
46
47 assert(root);
48 assert(path);
49
50 assert(*path == '$');
51 const char *c = path;
52
55
58 break;
59 }
60
61 const uint8_t *bytes = (uint8_t *) c + matches[1].location;
62 const size_t length = matches[1].
length;
63
65 if (*segment->
chars ==
'.') {
66
69
71
73
75
76 }
else if (*segment->
chars ==
'[') {
77
79 const unsigned long index = strtoul(segment->
chars + 1, NULL, 10);
80 if (index < array->count) {
82 } else {
84 }
85 }
87
88 c += length;
89 }
90
92}
static ident objectAtIndex(const Array *self, size_t index)
static Array * array(void)
#define cast(type, obj)
Safely cast obj to type.
static Dictionary * dictionary(void)
static ident objectForKey(const Dictionary *self, const ident key)
static bool matchesCharacters(const Regexp *self, const char *chars, int options, Range **ranges)
static String * substring(const String *self, const Range range)
static String * stringWithBytes(const uint8_t *bytes, size_t length, StringEncoding encoding)
void * ident
The identity type, similar to Objective-C id.
A location and length into contiguous collections.
ssize_t location
The location.
char * chars
The backing null-terminated UTF-8 encoded character array.
size_t length
The length of the String in bytes.
◆ _re