home *** CD-ROM | disk | FTP | other *** search
- // ansibuf.hpp
- //
- // Created 02/07/98
- //
- // (C)Copyright 1998-1999 Microsoft Corporation, All rights reserved.
- //
-
- #ifndef __ANSIBUF_HPP__
- #define __ANSIBUF_HPP__
-
-
- class ANSIStringBuffer
- {
- PSTR m_str;
- int m_len;
- int m_size;
-
- // Ensures that 'needed' chars + '\0' can fit into buffer
- BOOL EnsureSpace (int needed);
-
- public:
-
- ANSIStringBuffer ()
- {
- m_str = NULL;
- m_len = 0;
- m_size = 0;
- }
-
- ~ANSIStringBuffer ()
- {
- if (m_str)
- delete(m_str);
- }
-
- BOOL Append (PWSTR pwstr)
- {
- int len = WideCharToMultiByte(CP_ACP, 0, pwstr, -1, NULL, 0, NULL, NULL);
- if (len >= 0)
- {
- if (EnsureSpace(len-1))
- {
- if (WideCharToMultiByte(CP_ACP, 0, pwstr, -1, m_str+m_len, len, NULL, NULL) >= 0)
- {
- m_len += len-1;
- return TRUE;
- }
- else
- {
- // if WC2MB tromped on the buffer, ensure it remains as it was.
- m_str[m_len] = '\0';
- }
- }
- }
- return FALSE;
- }
-
- BOOL Append (PCSTR pstr)
- {
- int len = strlen(pstr);
- if (EnsureSpace(len))
- {
- CopyMemory(m_str+m_len, pstr, len+1);
- m_len += len;
- return TRUE;
- }
- return FALSE;
- }
-
- BOOL AppendUtf8 (PCSTR putf8);
-
- PSTR GetStr ()
- {
- return m_str;
- }
-
- PSTR SnatchStr ()
- {
- PSTR ret = m_str;
- m_str = NULL;
- m_size = 0;
- m_len = 0;
- return ret;
- }
-
- int GetLength ()
- {
- return m_len;
- }
- };
-
-
- #endif /* __ANSIBUF_HPP__ */
-
-