File indexing completed on 2025-01-19 03:55:17
0001 /*****************************************************************************/ 0002 // Copyright 2006-2019 Adobe Systems Incorporated 0003 // All Rights Reserved. 0004 // 0005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 0006 // accordance with the terms of the Adobe license agreement accompanying it. 0007 /*****************************************************************************/ 0008 0009 /** \file 0010 * Text string representation. 0011 */ 0012 0013 /*****************************************************************************/ 0014 0015 #ifndef __dng_string__ 0016 #define __dng_string__ 0017 0018 /*****************************************************************************/ 0019 0020 #include "dng_types.h" 0021 #include "dng_memory.h" 0022 0023 /*****************************************************************************/ 0024 0025 class dng_string 0026 { 0027 0028 private: 0029 0030 // Always stored internally as a UTF-8 encoded string. 0031 0032 dng_memory_data fData; 0033 0034 public: 0035 0036 dng_string (); 0037 0038 dng_string (const dng_string &s); 0039 0040 dng_string & operator= (const dng_string &s); 0041 0042 ~dng_string (); 0043 0044 const char * Get () const; 0045 0046 bool IsASCII () const; 0047 0048 void Set (const char *s); 0049 0050 void Set_ASCII (const char *s); 0051 0052 void Set_UTF8 (const char *s); 0053 0054 uint32 Get_SystemEncoding (dng_memory_data &buffer) const; 0055 0056 void Set_SystemEncoding (const char *s); 0057 0058 bool ValidSystemEncoding () const; 0059 0060 void Set_JIS_X208_1990 (const char *s); 0061 0062 static uint32 DecodeUTF8 (const char *&s, 0063 uint32 maxBytes = 6, 0064 bool *isValid = NULL); 0065 0066 static bool IsUTF8 (const char *s); 0067 0068 void Set_UTF8_or_System (const char *s); 0069 0070 uint32 Get_UTF16 (dng_memory_data &buffer) const; 0071 0072 void Set_UTF16 (const uint16 *s); 0073 0074 void Clear (); 0075 0076 void Truncate (uint32 maxBytes); 0077 0078 bool TrimTrailingBlanks (); 0079 0080 bool TrimLeadingBlanks (); 0081 0082 bool IsEmpty () const; 0083 0084 bool NotEmpty () const 0085 { 0086 return !IsEmpty (); 0087 } 0088 0089 uint32 Length () const; 0090 0091 bool operator== (const dng_string &s) const; 0092 0093 bool operator!= (const dng_string &s) const 0094 { 0095 return !(*this == s); 0096 } 0097 0098 // A utility for doing case insensitive comparisons on strings... 0099 0100 static bool Matches (const char *t, 0101 const char *s, 0102 bool case_sensitive = false); 0103 0104 // ...wrapped up for use with dng_string. 0105 0106 bool Matches (const char *s, 0107 bool case_sensitive = false) const; 0108 0109 bool StartsWith (const char *s, 0110 bool case_sensitive = false) const; 0111 0112 bool EndsWith (const char *s, 0113 bool case_sensitive = false) const; 0114 0115 bool Contains (const char *s, 0116 bool case_sensitive = false, 0117 int32 *match_offset = NULL) const; 0118 0119 bool Replace (const char *old_string, 0120 const char *new_string, 0121 bool case_sensitive = true); 0122 0123 void ReplaceChars (char oldChar, 0124 char newChar); 0125 0126 bool TrimLeading (const char *s, 0127 bool case_sensitive = false); 0128 0129 void Append (const char *s); 0130 0131 void SetUppercase (); 0132 0133 void SetLowercase (); 0134 0135 void SetLineEndings (char ending); 0136 0137 void SetLineEndingsToNewLines () 0138 { 0139 SetLineEndings ('\n'); 0140 } 0141 0142 void SetLineEndingsToReturns () 0143 { 0144 SetLineEndings ('\r'); 0145 } 0146 0147 void StripLowASCII (); 0148 0149 void ForceASCII (); 0150 0151 int32 Compare (const dng_string &s, 0152 bool digitsAsNumber = true) const; 0153 0154 // A utility to convert fields of numbers into comma separated numbers. 0155 0156 void NormalizeAsCommaSeparatedNumbers (); 0157 0158 }; 0159 0160 /*****************************************************************************/ 0161 0162 #endif 0163 0164 /*****************************************************************************/