aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-10-04 10:22:46 +1300
committerArslaan Pathan <[email protected]>2026-10-04 10:22:46 +1300
commit9e1ee2c8c964f74163559dc12aba5def1ff5366a (patch)
tree5d2495b1f42ac7c0a3ed4d4a55541af2a629e096
parentae0868c1c4ea35071381319bb32721acd60f95ce (diff)
downloadParadox-9e1ee2c8c964f74163559dc12aba5def1ff5366a.tar.xz
Paradox-9e1ee2c8c964f74163559dc12aba5def1ff5366a.zip
basic PXString implementation
-rw-r--r--src/String.m59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/String.m b/src/String.m
new file mode 100644
index 0000000..7d5d4d8
--- /dev/null
+++ b/src/String.m
@@ -0,0 +1,59 @@
+#include <objc/objc.h>
+#include <objc/runtime.h>
+#include <Paradox/Object.h>
+#include <Paradox/String.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+@implementation PXString
+
+/* init/lifecycle */
+
++ (instancetype)stringWithCString:(const char *)cstring {
+ PXString *string = [PXString alloc];
+ return [string initWithCString:cstring];
+}
+
+- (instancetype)init {
+ return [self initWithCString:""];
+}
+
+- (instancetype)initWithCString:(const char *)cstring {
+ self = [super init];
+ if (self) {
+ if (cstring == NULL)
+ cstring = "";
+
+ _length = strlen(cstring);
+ _bytes = malloc(_length + 1);
+ memcpy(_bytes, cstring, _length + 1);
+ }
+ return self;
+}
+
+- (void)dealloc {
+ free(_bytes);
+ [super dealloc];
+}
+
+/* getters */
+- (const char *)UTF8String {
+ return _bytes;
+}
+
+- (size_t)length {
+ return _length;
+}
+
+- (BOOL)isEqual:(PXString *)string {
+ if (self == string)
+ return YES;
+
+ if (string == nil || _length != string->_length)
+ return NO;
+
+ return (memcmp(_bytes, string->_bytes, _length) == 0);
+}
+
+@end