Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name: Shell String Class
  4. shstr.h
  5. Author:
  6. Zeke Lucas (zekel) 27-Oct-96
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. Abstract:
  11. this allows automatic resizing and stuff
  12. NOTE: this class is specifically designed to be used as a stack variable
  13. --*/
  14. #ifndef _SHSTR_H_
  15. // default shstr to something small, so we don't waste too much stack space
  16. // MAX_PATH is used frequently, so we'd like to a factor of that - so that
  17. // if we do grow to MAX_PATH size, we don't waste any extra.
  18. #define DEFAULT_SHSTR_LENGTH (MAX_PATH/4)
  19. #ifdef UNICODE
  20. #define ShStr ShStrW
  21. #define UrlStr UrlStrW
  22. #else
  23. #define ShStr ShStrA
  24. #define UrlStr UrlStrA
  25. #endif //UNICODE
  26. class ShStrA
  27. {
  28. public:
  29. //
  30. // Constructors
  31. //
  32. ShStrA();
  33. //
  34. // Destructor
  35. //
  36. ~ShStrA()
  37. {Reset();}
  38. //
  39. // the first are the only ones that count
  40. //
  41. HRESULT SetStr(LPCSTR pszStr, DWORD cchStr);
  42. HRESULT SetStr(LPCSTR pszStr);
  43. HRESULT SetStr(LPCWSTR pwszStr, DWORD cchStr);
  44. // the rest just call into the first three
  45. HRESULT SetStr(LPCWSTR pwszStr)
  46. {return SetStr(pwszStr, (DWORD) -1);}
  47. HRESULT SetStr(ShStrA &shstr)
  48. {return SetStr(shstr._pszStr);}
  49. ShStrA& operator=(LPCSTR pszStr)
  50. {SetStr(pszStr); return *this;}
  51. ShStrA& operator=(LPCWSTR pwszStr)
  52. {SetStr(pwszStr); return *this;}
  53. ShStrA& operator=(ShStrA &shstr)
  54. {SetStr(shstr._pszStr); return *this;}
  55. LPCSTR GetStr()
  56. {return _pszStr;}
  57. operator LPCSTR()
  58. {return _pszStr;}
  59. LPSTR GetInplaceStr(void)
  60. {return _pszStr;}
  61. // People want to play with the bytes in OUR internal buffer. If they
  62. // call us correctly, and assume that the resulting pointer is only valid
  63. // as far as they want or as far as the current length, then let them.
  64. LPSTR GetModifyableStr(DWORD cchSizeToModify)
  65. {
  66. if (cchSizeToModify > _cchSize)
  67. if (FAILED(SetSize(cchSizeToModify)))
  68. return NULL;
  69. return _pszStr;
  70. }
  71. HRESULT Append(LPCSTR pszStr, DWORD cchStr);
  72. HRESULT Append(LPCSTR pszStr)
  73. {return Append(pszStr, (DWORD) -1);}
  74. HRESULT Append(CHAR ch)
  75. {return Append(&ch, 1);}
  76. //
  77. // the Clone methods return memory that must be freed
  78. //
  79. ShStrA *Clone();
  80. LPSTR CloneStrA();
  81. LPWSTR CloneStrW();
  82. LPSTR CloneStr()
  83. {return CloneStrA();}
  84. VOID Reset();
  85. VOID Trim();
  86. #ifdef DEBUG
  87. BOOL IsValid();
  88. #else
  89. inline BOOL IsValid()
  90. {return _pszStr != NULL;}
  91. #endif //DEBUG
  92. DWORD GetSize()
  93. {ASSERT(!(_cchSize % DEFAULT_SHSTR_LENGTH)); return (_pszStr ? _cchSize : 0);}
  94. HRESULT SetSize(DWORD cchSize);
  95. DWORD GetLen()
  96. {return lstrlenA(_pszStr);}
  97. protected:
  98. // friend UrlStr;
  99. /*
  100. TCHAR GetAt(DWORD cch)
  101. {return cch < _cchSize ? _pszStr[cch] : TEXT('\0');}
  102. TCHAR SetAt(TCHAR ch, DWORD cch)
  103. {return cch < _cchSize ? _pszStr[cch] = ch : TEXT('\0');}
  104. */
  105. private:
  106. HRESULT _SetStr(LPCSTR psz);
  107. HRESULT _SetStr(LPCSTR psz, DWORD cb);
  108. HRESULT _SetStr(LPCWSTR pwszStr, DWORD cchStr);
  109. CHAR _szDefaultBuffer[DEFAULT_SHSTR_LENGTH];
  110. LPSTR _pszStr;
  111. DWORD _cchSize;
  112. }; //ShStrA
  113. class ShStrW
  114. {
  115. public:
  116. //
  117. // Constructors
  118. //
  119. ShStrW();
  120. //
  121. // Destructor
  122. //
  123. ~ShStrW()
  124. {Reset();}
  125. //
  126. // the first are the only ones that count
  127. //
  128. HRESULT SetStr(LPCSTR pszStr, DWORD cchStr);
  129. HRESULT SetStr(LPCSTR pszStr);
  130. HRESULT SetStr(LPCWSTR pwszStr, DWORD cchStr);
  131. // the rest just call into the first three
  132. HRESULT SetStr(LPCWSTR pwszStr)
  133. {return SetStr(pwszStr, (DWORD) -1);}
  134. HRESULT SetStr(ShStrW &shstr)
  135. {return SetStr(shstr._pszStr);}
  136. ShStrW& operator=(LPCSTR pszStr)
  137. {SetStr(pszStr); return *this;}
  138. ShStrW& operator=(LPCWSTR pwszStr)
  139. {SetStr(pwszStr); return *this;}
  140. ShStrW& operator=(ShStrW &shstr)
  141. {SetStr(shstr._pszStr); return *this;}
  142. LPCWSTR GetStr()
  143. {return _pszStr;}
  144. operator LPCWSTR()
  145. {return _pszStr;}
  146. LPWSTR GetInplaceStr(void)
  147. {return _pszStr;}
  148. // People want to play with the bytes in OUR internal buffer. If they
  149. // call us correctly, and assume that the resulting pointer is only valid
  150. // as far as they want or as far as the current length, then let them.
  151. LPWSTR GetModifyableStr(DWORD cchSizeToModify)
  152. {
  153. if (cchSizeToModify > _cchSize)
  154. if (FAILED(SetSize(cchSizeToModify)))
  155. return NULL;
  156. return _pszStr;
  157. }
  158. HRESULT Append(LPCWSTR pszStr, DWORD cchStr);
  159. HRESULT Append(LPCWSTR pszStr)
  160. {return Append(pszStr, (DWORD) -1);}
  161. HRESULT Append(WCHAR ch)
  162. {return Append(&ch, 1);}
  163. //
  164. // the Clone methods return memory that must be freed
  165. //
  166. ShStrW *Clone();
  167. LPSTR CloneStrA();
  168. LPWSTR CloneStrW();
  169. LPWSTR CloneStr()
  170. {return CloneStrW();}
  171. VOID Reset();
  172. VOID Trim();
  173. #ifdef DEBUG
  174. BOOL IsValid();
  175. #else
  176. BOOL IsValid()
  177. {return (BOOL) (_pszStr ? TRUE : FALSE);}
  178. #endif //DEBUG
  179. DWORD GetSize()
  180. {ASSERT(!(_cchSize % DEFAULT_SHSTR_LENGTH)); return (_pszStr ? _cchSize : 0);}
  181. HRESULT SetSize(DWORD cchSize);
  182. DWORD GetLen()
  183. {return lstrlenW(_pszStr);}
  184. protected:
  185. // friend UrlStr;
  186. /*
  187. TCHAR GetAt(DWORD cch)
  188. {return cch < _cchSize ? _pszStr[cch] : TEXT('\0');}
  189. TCHAR SetAt(TCHAR ch, DWORD cch)
  190. {return cch < _cchSize ? _pszStr[cch] = ch : TEXT('\0');}
  191. */
  192. private:
  193. HRESULT _SetStr(LPCSTR psz);
  194. HRESULT _SetStr(LPCSTR psz, DWORD cb);
  195. HRESULT _SetStr(LPCWSTR pwszStr, DWORD cchStr);
  196. WCHAR _szDefaultBuffer[DEFAULT_SHSTR_LENGTH];
  197. LPWSTR _pszStr;
  198. DWORD _cchSize;
  199. }; //ShStrW
  200. #ifdef UNICODE
  201. typedef ShStrW SHSTR;
  202. typedef ShStrW *PSHSTR;
  203. #else
  204. typedef ShStrA SHSTR;
  205. typedef ShStrA *PSHSTR;
  206. #endif //UNICODE
  207. typedef ShStrW SHSTRW;
  208. typedef ShStrW *PSHSTRW;
  209. typedef ShStrA SHSTRA;
  210. typedef ShStrA *PSHSTRA;
  211. #if 0 //DISABLED until i have written the SHUrl* functions - zekel 7-Nov-96
  212. class UrlStr
  213. {
  214. public:
  215. UrlStr()
  216. {return;}
  217. operator LPCTSTR();
  218. operator SHSTR();
  219. UrlStr &SetUrl(LPCSTR pszUrl);
  220. UrlStr &SetUrl(LPCWSTR pwszUrl);
  221. UrlStr &SetUrl(LPCSTR pszUrl, DWORD cchUrl);
  222. UrlStr &SetUrl(LPCWSTR pwszUrl, DWORD cchUrl);
  223. DWORD GetScheme();
  224. VOID GetSchemeStr(PSHSTR pstrScheme);
  225. HRESULT Combine(LPCTSTR pszUrl, DWORD dwFlags);
  226. /*
  227. ShStr &GetLocation();
  228. ShStr &GetAnchor();
  229. ShStr &GetQuery();
  230. HRESULT Canonicalize(DWORD dwFlags);
  231. */
  232. protected:
  233. SHSTR _strUrl;
  234. };
  235. #endif //DISABLED
  236. #endif // _SHSTR_H_