Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Properties | Methods | Protected Attributes
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

Stringfragment
 The fragment. More...
 
Stringhost
 The host. More...
 
Object object
 The superclass. More...
 
Stringpath
 The path. More...
 
unsigned short port
 The port. More...
 
Stringquery
 The query. More...
 
Stringscheme
 The scheme, or protocol. More...
 
StringurlString
 The URL String. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_URL (void)
 The URL archetype. More...
 
URLbaseURL (const URL *self)
 
URLinitWithCharacters (URL *self, const char *chars)
 Initializes this URL with the specified characters. More...
 
URLinitWithString (URL *self, const String *string)
 Initializes this URL with the specified String. More...
 
ArraypathComponents (const URL *self)
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

URLInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

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
protected

The interface.

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 .interfaceOffset = offsetof(URL, interface),
258 .interfaceSize = sizeof(URLInterface),
260 .destroy = destroy,
261 });
262 });
263
264 return clazz;
265}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void destroy(Class *clazz)
Definition: URL.c:239
static void initialize(Class *clazz)
Definition: URL.c:220
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:95
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136
Uniform Resource Locators (RFC 3986).
Definition: URL.h:44
URLInterface * interface
The interface.
Definition: URL.h:55

◆ 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 MutableString *string = $(alloc(MutableString), 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:196
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
static void appendFormat(MutableString *self, const char *fmt,...)
Definition: MutableString.c:89
static void appendString(MutableString *self, const String *string)
Mutable UTF-8 strings.
Definition: MutableString.h:40
Object * init(Object *self)
Initializes this Object.
Definition: Object.c:83
Immutable 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 _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:539
static Regexp * _re
Definition: URL.c:130
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 MutableString * string(void)

◆ 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:184

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