summaryrefslogtreecommitdiff
path: root/source/dng_string.h
blob: 41608f128b299ae82d64c1118f4a766717132ebd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*****************************************************************************/
// Copyright 2006-2007 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
// accordance with the terms of the Adobe license agreement accompanying it.
/*****************************************************************************/

/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_string.h#2 $ */ 
/* $DateTime: 2012/07/31 22:04:34 $ */
/* $Change: 840853 $ */
/* $Author: tknoll $ */

/** \file
 * Text string representation.
 */

/*****************************************************************************/

#ifndef __dng_string__
#define __dng_string__

/*****************************************************************************/

#include "dng_types.h"
#include "dng_memory.h"

/*****************************************************************************/

class dng_string
	{
	
	private:
	
		// Always stored internally as a UTF-8 encoded string.
	
		dng_memory_data fData;
		
	public:
	
		dng_string ();
		
		dng_string (const dng_string &s);
		
		dng_string & operator= (const dng_string &s);
		
		~dng_string ();
		
		const char * Get () const;
		
		bool IsASCII () const;
		
		void Set (const char *s);
	
		void Set_ASCII (const char *s);
		
		void Set_UTF8 (const char *s);
		
		uint32 Get_SystemEncoding (dng_memory_data &buffer) const;
		
		void Set_SystemEncoding (const char *s);
		
		bool ValidSystemEncoding () const;
		
		void Set_JIS_X208_1990 (const char *s);
				  
		static uint32 DecodeUTF8 (const char *&s,
								  uint32 maxBytes = 6,
								  bool *isValid = NULL);
								  
		static bool IsUTF8 (const char *s);
		
		void Set_UTF8_or_System (const char *s);

		uint32 Get_UTF16 (dng_memory_data &buffer) const;
		
		void Set_UTF16 (const uint16 *s);
		
		void Clear ();
		
		void Truncate (uint32 maxBytes);
		
		bool TrimTrailingBlanks ();
		
		bool TrimLeadingBlanks ();
		
		bool IsEmpty () const;
		
		bool NotEmpty () const
			{
			return !IsEmpty ();
			}
			
		uint32 Length () const;
		
		bool operator== (const dng_string &s) const;
		
		bool operator!= (const dng_string &s) const
			{
			return !(*this == s);
			}
			
		// A utility for doing case insensitive comparisons on strings...
		
		static bool Matches (const char *t,
							 const char *s,
							 bool case_sensitive = false);
							 
		// ...wrapped up for use with dng_string.

		bool Matches (const char *s,
					  bool case_sensitive = false) const;

		bool StartsWith (const char *s,
						 bool case_sensitive = false) const;
						 
		bool EndsWith (const char *s,
					   bool case_sensitive = false) const;
					   
		bool Contains (const char *s,
					   bool case_sensitive = false,
					   int32 *match_offset = NULL) const;
						 
		bool Replace (const char *old_string,
					  const char *new_string,
					  bool case_sensitive = true);
		
		bool TrimLeading (const char *s,
						  bool case_sensitive = false);
						  
		void Append (const char *s);
		
		void SetUppercase ();
		
		void SetLowercase ();
		
		void SetLineEndings (char ending);
		
		void SetLineEndingsToNewLines ()
			{
			SetLineEndings ('\n');
			}
			
		void SetLineEndingsToReturns ()
			{
			SetLineEndings ('\r');
			}
			
		void StripLowASCII ();
		
		void ForceASCII ();
		
		int32 Compare (const dng_string &s) const;

		// A utility to convert fields of numbers into comma separated numbers.

		void NormalizeAsCommaSeparatedNumbers ();

	};
	
/*****************************************************************************/

#endif
	
/*****************************************************************************/