summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-08 19:40:02 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-08 19:40:02 -0700
commite8718306a5bc688bea31c03d52b997166f0ba578 (patch)
treeec04fb32519464a046f7f442af89b86bcb870837 /src
parent35b5a016c20a6ce1f679a377005900b190dedfa1 (diff)
Bugfix and additions to upb.h and upb_string.h
Diffstat (limited to 'src')
-rw-r--r--src/upb.h1
-rw-r--r--src/upb_string.h17
2 files changed, 17 insertions, 1 deletions
diff --git a/src/upb.h b/src/upb.h
index 64f2c54..685a292 100644
--- a/src/upb.h
+++ b/src/upb.h
@@ -36,6 +36,7 @@ extern "C" {
#define UPB_INDEX(base, i, m) (void*)((char*)(base) + ((i)*(m)))
INLINE uint32_t max(uint32_t a, uint32_t b) { return a > b ? a : b; }
+INLINE uint32_t min(uint32_t a, uint32_t b) { return a < b ? a : b; }
/* Value type as defined in a .proto file. The values of this are defined by
* google_protobuf_FieldDescriptorProto_Type (from descriptor.proto).
diff --git a/src/upb_string.h b/src/upb_string.h
index 7a05811..de2384d 100644
--- a/src/upb_string.h
+++ b/src/upb_string.h
@@ -43,8 +43,15 @@ INLINE bool upb_streql(struct upb_string *s1, struct upb_string *s2) {
memcmp(s1->ptr, s2->ptr, s1->byte_len) == 0;
}
+INLINE int upb_strcmp(struct upb_string s1, struct upb_string s2) {
+ size_t common_length = min(s1.byte_len, s2.byte_len);
+ int common_diff = memcmp(s1.ptr, s2.ptr, common_length);
+ if(common_diff == 0) return s1.byte_len - s2.byte_len;
+ else return common_diff;
+}
+
INLINE void upb_strcpy(struct upb_string *dest, struct upb_string *src) {
- memcpy(dest->ptr, src->ptr, dest->byte_len);
+ memcpy(dest->ptr, src->ptr, src->byte_len);
dest->byte_len = src->byte_len;
}
@@ -56,6 +63,14 @@ INLINE struct upb_string upb_strdup(struct upb_string s) {
return copy;
}
+INLINE struct upb_string upb_strdupc(char *s) {
+ struct upb_string copy;
+ copy.byte_len = strlen(s);
+ copy.ptr = (char*)malloc(copy.byte_len);
+ memcpy(copy.ptr, s, copy.byte_len);
+ return copy;
+}
+
INLINE void upb_strfree(struct upb_string s) {
free(s.ptr);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback