Permalink
Browse files

added function to append parameter to a url string

  • Loading branch information...
ettore committed Oct 11, 2012
1 parent 2f91457 commit e223d5a0b9a82d7c7ed369509d2e9d175d2eac48
Showing with 20 additions and 1 deletion.
  1. +6 −1 clcg_str_utils.h
  2. +14 −0 clcg_str_utils.m
View
@@ -28,7 +28,12 @@
#ifdef __cplusplus
extern "C" {
#endif
-
+
+ // given a url string, append the given parameter to it.
+ extern NSString *clcg_str_append2url(NSString *url,
+ NSString *param_name,
+ NSString *param_val);
+
// returns YES if string are equal (or both nil), NO otherwise
extern BOOL clcg_str_eq(NSString *s, NSString *t);
View
@@ -26,6 +26,20 @@
#import "clcg_str_utils.h"
+NSString *clcg_str_append2url(NSString *url,
+ NSString *param_name,
+ NSString *param_val)
+{
+ if (url == nil)
+ return nil;
+
+ NSRange r = [url rangeOfString:@"?"];
+ char c = ((r.location == NSNotFound) ? '?' : '&');
+
+ return [NSString stringWithFormat:@"%@%c%@=%@",url,c,param_name,param_val];
+}
+
+
BOOL clcg_str_eq(NSString *s, NSString *t)
{
if (s == nil && t == nil)

0 comments on commit e223d5a

Please sign in to comment.