commit 87a46d2bfd150ebe89da89be1cdba4fdc620bfa0
parent 97acb934ae410fc8a9be51f3272d7b504750eec5
Author: ByteProject <stefan.vogt@byteproject.net>
Date: Wed, 21 Dec 2011 10:58:07 +0100
implementation of PHP's substr() in ANSI C
Diffstat:
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/ansilove/substr.h b/ansilove/substr.h
@@ -0,0 +1,16 @@
+//
+// substr.h
+// AnsiLove/ObjC
+//
+// Copyright (c) 2011, Stefan Vogt. All rights reserved.
+// http://byteproject.net
+//
+// Use of this source code is governed by a MIT-style license.
+// See the file LICENSE for details.
+//
+
+#import <Foundation/Foundation.h>
+
+// Returns the portion of a string specified by start and length parameters.
+
+char *substring(const char *str, size_t begin, size_t len);
diff --git a/ansilove/substr.m b/ansilove/substr.m
@@ -0,0 +1,20 @@
+//
+// substr.m
+// AnsiLove/ObjC
+//
+// Copyright (c) 2011, Stefan Vogt. All rights reserved.
+// http://byteproject.net
+//
+// Use of this source code is governed by a MIT-style license.
+// See the file LICENSE for details.
+//
+
+#import "substr.h"
+
+char *substring(const char *str, size_t begin, size_t len)
+{
+ if (str == 0 || strlen(str) == 0 || strlen(str) < begin || strlen(str) < (begin+len))
+ return 0;
+
+ return strndup(str + begin, len);
+}