new String8, String16 ctors to initialize empty static strings with static linkage
when libutils is statically linked, the ordering of the static
initializer is not guaranteed and therefore it's unsafe to use
empty static strings: e.g.:
static String8 sThisStaticStringIsNotSafe;
instead, this new constructor can be used:
static String8 sThisStaticStringIsSafe(kEmptyString);
Change-Id: Ia3daf1cab1c97d021c0ee9c2b394b5e27e8d6c0d
diff --git a/include/utils/String8.h b/include/utils/String8.h
index 9426fcf..ef59470 100644
--- a/include/utils/String8.h
+++ b/include/utils/String8.h
@@ -37,7 +37,16 @@
class String8
{
public:
+ /* use String8(StaticLinkage) if you're statically linking against
+ * libutils and declaring an empty static String8, e.g.:
+ *
+ * static String8 sAStaticEmptyString(String8::kEmptyString);
+ * static String8 sAnotherStaticEmptyString(sAStaticEmptyString);
+ */
+ enum StaticLinkage { kEmptyString };
+
String8();
+ explicit String8(StaticLinkage);
String8(const String8& o);
explicit String8(const char* o);
explicit String8(const char* o, size_t numChars);