Objectively
Object oriented framework for C.
Loading...
Searching...
No Matches
URL Struct Reference

#include <URL.h>

Overview

Uniform Resource Locators (RFC 3986).

See also
http://www.ietf.org/rfc/rfc3986.txt

Definition at line 44 of file URL.h.

Inheritance diagram for URL:
Object

Properties

String * fragment
 The fragment.
 
String * host
 The host.
 
Object object
 The superclass.
 
String * path
 The path.
 
unsigned short port
 The port.
 
String * query
 The query.
 
String * scheme
 The scheme, or protocol.
 
String * urlString
 The URL String.
 
- Properties inherited from Object
Class * clazz
 Every instance of Object begins with a pointer to its Class.
 
unsigned int magic
 A header to allow introspection of Object types.
 

Methods

Class * _URL (void)
 The URL archetype.
 
URL * baseURL (const URL *self)
 
URL * initWithCharacters (URL *self, const char *chars)
 Initializes this URL with the specified characters.
 
URL * initWithString (URL *self, const String *string)
 Initializes this URL with the specified String.
 
Array * pathComponents (const URL *self)
 
- Methods inherited from Object
Class * _Object (void)
 The Object archetype.
 
Object * copy (const Object *self)
 Creates a shallow copy of this Object.
 
void dealloc (Object *self)
 Frees all resources held by this Object.
 
String * description (const Object *self)
 
int hash (const Object *self)
 
Object * init (Object *self)
 Initializes this Object.
 
bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object.
 
bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership.
 

Protected Attributes

URLInterface * interface [0]
 The interface type.
 
- Protected Attributes inherited from Object
ObjectInterface * interface [0]
 The interface type.
 

Property Details

◆ fragment

String* URL::fragment

The fragment.

Definition at line 60 of file URL.h.

◆ host

String* URL::host

The host.

Definition at line 65 of file URL.h.

◆ interface

URLInterface* URL::interface[0]
protected

The interface type.

Definition at line 55 of file URL.h.

◆ object

Object URL::object

The superclass.

Definition at line 49 of file URL.h.

◆ path

String* URL::path

The path.

Definition at line 70 of file URL.h.

◆ port

unsigned short URL::port

The port.

Definition at line 75 of file URL.h.

◆ query

String* URL::query

The query.

Definition at line 80 of file URL.h.

◆ scheme

String* URL::scheme

The scheme, or protocol.

Definition at line 85 of file URL.h.

◆ urlString

String* URL::urlString

The URL String.

Definition at line 90 of file URL.h.

Method Details

◆ _URL()

Class * _URL ( void  )

The URL archetype.

Returns
The URL Class.

Definition at line 248 of file URL.c.

248 {
249 static Class *clazz;
250 static Once once;
251
252 do_once(&once, {
253 clazz = _initialize(&(const ClassDef) {
254 .name = "URL",
255 .superclass = _Object(),
256 .instanceSize = sizeof(URL),
257 .interfaceSize = sizeof(URLInterface),
258 .initialize = initialize,
259 .destroy = destroy,
260 });
261 });
262
263 return clazz;
264}
static void initialize(Class *clazz)
Definition Array.c:710
static void destroy(Class *clazz)
Definition Boole.c:102
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:151
long Once
The Once type.
Definition Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition Class.h:41
The runtime representation of a Class.
Definition Class.h:90
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition Object.h:55
Class * _Object(void)
The Object archetype.
Definition Object.c:136
Uniform Resource Locators (RFC 3986).
Definition URL.h:44

◆ baseURL()

URL * baseURL ( const URL *  self)
Parameters
selfThe URL.
Returns
The base URL (scheme, host, and port) of this URL.

Definition at line 108 of file URL.c.

108 {
109
110 String *string = $(alloc(String), init);
111
112 $(string, appendString, self->scheme);
113 $(string, appendFormat, "://");
114
115 if (self->host) {
116 $(string, appendString, self->host);
117 }
118
119 if (self->port) {
120 $(string, appendFormat, ":%u", self->port);
121 }
122
123 URL *baseURL = $(alloc(URL), initWithString, (String *) string);
124
125 release(string);
126
127 return baseURL;
128}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition Class.c:356
#define alloc(type)
Allocate and initialize and instance of type.
Definition Class.h:226
static void appendFormat(String *self, const char *fmt,...)
Definition String.c:536
static void appendString(String *self, const String *string)
Definition String.c:550
Object * init(Object *self)
Initializes this Object.
Definition Object.c:83
UTF-8 strings.
Definition String.h:69
unsigned short port
The port.
Definition URL.h:75
URL * baseURL(const URL *self)
Definition URL.c:108
String * scheme
The scheme, or protocol.
Definition URL.h:85
URL * initWithString(URL *self, const String *string)
Initializes this URL with the specified String.
Definition URL.c:199
String * host
The host.
Definition URL.h:65

◆ initWithCharacters()

URL * initWithCharacters ( URL *  self,
const char *  chars 
)

Initializes this URL with the specified characters.

Parameters
selfThe URL.
charsThe URL characters.
Returns
The initialized URL, or NULL on error.

Definition at line 136 of file URL.c.

136 {
137
138 assert(chars);
139
140 self = (URL *) super(Object, self, init);
141 if (self) {
142
143 Range *ranges;
144 if ($(_re, matchesCharacters, chars, 0, &ranges)) {
145
146 self->urlString = $(alloc(String), initWithCharacters, chars);
147
148 Range *scheme = &ranges[1];
149 Range *host = &ranges[2];
150 Range *port = &ranges[3];
151 Range *path = &ranges[4];
152 Range *query = &ranges[5];
153 Range *fragment = &ranges[6];
154
155 self->scheme = $(self->urlString, substring, *scheme);
156
157 if (host->location > -1) {
158 self->host = $(self->urlString, substring, *host);
159
160 if (port->location > -1) {
161 const char *s = self->urlString->chars + port->location + 1;
162 self->port = strtoul(s, NULL, 10);
163 }
164 }
165
166 if (path->location > -1) {
167 self->path = $(self->urlString, substring, *path);
168 }
169
170 if (query->location > -1) {
171
172 query->location++;
173 query->length--;
174
175 self->query = $(self->urlString, substring, *query);
176 }
177
178 if (fragment->location > -1) {
179
180 fragment->location++;
181 fragment->length--;
182
183 self->fragment = $(self->urlString, substring, *fragment);
184 }
185
186 free(ranges);
187 } else {
188 self = release(self);
189 }
190 }
191
192 return self;
193}
#define super(type, obj, method,...)
static Regexp * _re
Definition JSONPath.c:39
static bool matchesCharacters(const Regexp *self, const char *chars, int options, Range **ranges)
Definition Regexp.c:134
static String * substring(const String *self, const Range range)
Definition String.c:401
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
A location and length into contiguous collections.
Definition Types.h:54
char * chars
The backing null-terminated UTF-8 encoded character array.
Definition String.h:85
size_t length
The length of the String in bytes.
Definition String.h:90
String * path
The path.
Definition URL.h:70
String * urlString
The URL String.
Definition URL.h:90
String * fragment
The fragment.
Definition URL.h:60
String * query
The query.
Definition URL.h:80
URL * initWithCharacters(URL *self, const char *chars)
Initializes this URL with the specified characters.
Definition URL.c:136

◆ initWithString()

URL * initWithString ( URL *  self,
const String *  string 
)

Initializes this URL with the specified String.

Parameters
selfThe URL.
stringThe URL String.
Returns
The initialized URL, or NULL on error.

Definition at line 199 of file URL.c.

199 {
200
201 assert(string);
202
203 return $(self, initWithCharacters, string->chars);
204}
static String * string(void)
Definition String.c:900

◆ pathComponents()

Array * pathComponents ( const URL *  self)
Parameters
selfThe URL.
Returns
The path components of this URL.

Definition at line 210 of file URL.c.

210 {
211
212 return $(self->path, componentsSeparatedByCharacters, "/");
213}
static Array * componentsSeparatedByCharacters(const String *self, const char *chars)
Definition String.c:182

The documentation for this struct was generated from the following files: