OSDN Git Service

stagefright: add AString parceling, and equal/compareIgnoreCase
authorLajos Molnar <lajos@google.com>
Wed, 6 Aug 2014 18:32:00 +0000 (11:32 -0700)
committerLajos Molnar <lajos@google.com>
Thu, 7 Aug 2014 21:23:27 +0000 (14:23 -0700)
Bug: 11990470
Change-Id: If43ada5d2e768931f4409e499eaa268edade0500

include/media/stagefright/foundation/AString.h
media/libstagefright/foundation/AString.cpp

index 4be3c6d..7c98699 100644 (file)
 
 #define A_STRING_H_
 
+#include <utils/Errors.h>
 #include <sys/types.h>
 
 namespace android {
 
 struct String8;
+struct Parcel;
 
 struct AString {
     AString();
@@ -77,7 +79,9 @@ struct AString {
     bool operator>(const AString &other) const;
 
     int compare(const AString &other) const;
+    int compareIgnoreCase(const AString &other) const;
 
+    bool equalsIgnoreCase(const AString &other) const;
     bool startsWith(const char *prefix) const;
     bool endsWith(const char *suffix) const;
     bool startsWithIgnoreCase(const char *prefix) const;
@@ -85,6 +89,9 @@ struct AString {
 
     void tolower();
 
+    static AString FromParcel(const Parcel &parcel);
+    status_t writeToParcel(Parcel *parcel) const;
+
 private:
     static const char *kEmptyString;
 
index 894f65c..1befef4 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <binder/Parcel.h>
 #include <utils/String8.h>
 #include "ADebug.h"
 #include "AString.h"
@@ -306,6 +307,14 @@ int AString::compare(const AString &other) const {
     return strcmp(mData, other.mData);
 }
 
+int AString::compareIgnoreCase(const AString &other) const {
+    return strcasecmp(mData, other.mData);
+}
+
+bool AString::equalsIgnoreCase(const AString &other) const {
+    return compareIgnoreCase(other) == 0;
+}
+
 void AString::tolower() {
     makeMutable();
 
@@ -342,6 +351,21 @@ bool AString::endsWithIgnoreCase(const char *suffix) const {
     return !strcasecmp(mData + mSize - suffixLen, suffix);
 }
 
+// static
+AString AString::FromParcel(const Parcel &parcel) {
+    size_t size = static_cast<size_t>(parcel.readInt32());
+    return AString(static_cast<const char *>(parcel.readInplace(size)), size);
+}
+
+status_t AString::writeToParcel(Parcel *parcel) const {
+    CHECK_LE(mSize, INT32_MAX);
+    status_t err = parcel->writeInt32(mSize);
+    if (err == OK) {
+        err = parcel->write(mData, mSize);
+    }
+    return err;
+}
+
 AString StringPrintf(const char *format, ...) {
     va_list ap;
     va_start(ap, format);