Audacity  2.2.0
Internat.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Internat.h
6 
7  Markus Meyer
8  Dominic Mazzoni (Mac OS X code)
9 
10 **********************************************************************/
11 
12 #ifndef __AUDACITY_INTERNAT__
13 #define __AUDACITY_INTERNAT__
14 
15 #include <wx/arrstr.h>
16 #include <wx/string.h>
17 #include <wx/longlong.h>
18 
19 class Internat
20 {
21 public:
24  static void Init();
25 
30  static wxChar GetDecimalSeparator();
31 
37  static bool CompatibleToDouble(const wxString& stringToConvert, double* result);
38 
39  // Function version of above.
40  static double CompatibleToDouble(const wxString& stringToConvert);
41 
44  static wxString ToString(double numberToConvert,
45  int digitsAfterDecimalPoint = -1);
46 
49  static wxString ToDisplayString(double numberToConvert,
50  int digitsAfterDecimalPoint = -1);
51 
54  static wxString FormatSize(wxLongLong size);
55  static wxString FormatSize(double size);
56 
59 #if defined(__WXMSW__)
60  static char *VerifyFilename(const wxString &s, bool input = true);
61 #endif
62 
68  static bool SanitiseFilename(wxString &name, const wxString &sub);
69 
77  static wxString StripAccelerators(const wxString& str);
78 
79  static wxString Parenthesize(const wxString &str);
80 
81  static const wxArrayString &GetExcludedCharacters()
82  { return exclude; }
83 
84 private:
85  static wxChar mDecimalSeparator;
86 
87  // stuff for file name sanitisation
88  static wxArrayString exclude;
89 
90  static wxCharBuffer mFilename;
91 };
92 
93 #define _NoAcc(X) Internat::StripAccelerators(_(X))
94 
95 // Use this macro to wrap all filenames and pathnames that get
96 // passed directly to a system call, like opening a file, creating
97 // a directory, checking to see that a file exists, etc...
98 #if defined(__WXMSW__)
99 // Note, on Windows we don't define an OSFILENAME() to prevent accidental use.
100 // See VerifyFilename() for an explanation.
101 #define OSINPUT(X) Internat::VerifyFilename(X, true)
102 #define OSOUTPUT(X) Internat::VerifyFilename(X, false)
103 #elif defined(__WXMAC__)
104 #define OSFILENAME(X) ((char *) (const char *)(X).fn_str())
105 #define OSINPUT(X) OSFILENAME(X)
106 #define OSOUTPUT(X) OSFILENAME(X)
107 #else
108 #define OSFILENAME(X) ((char *) (const char *)(X).mb_str())
109 #define OSINPUT(X) OSFILENAME(X)
110 #define OSOUTPUT(X) OSFILENAME(X)
111 #endif
112 
113 // Convert C strings to wxString
114 #define UTF8CTOWX(X) wxString((X), wxConvUTF8)
115 #define LAT1CTOWX(X) wxString((X), wxConvISO8859_1)
116 
117 #endif
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:190
static wxString StripAccelerators(const wxString &str)
Remove accelerator charactors from strings.
Definition: Internat.cpp:289
Internationalisation support.
Definition: Internat.h:19
static const wxArrayString & GetExcludedCharacters()
Definition: Internat.h:81
static void Init()
Initialize internationalisation support. Call this once at program start.
Definition: Internat.cpp:81
static bool SanitiseFilename(wxString &name, const wxString &sub)
Protect against Unicode to multi-byte conversion failures on Windows.
Definition: Internat.cpp:266
static wxString Parenthesize(const wxString &str)
Definition: Internat.cpp:302
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:137
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:121
static wxArrayString exclude
Definition: Internat.h:88
static wxChar mDecimalSeparator
Definition: Internat.h:85
const wxChar * name
Definition: Distortion.cpp:93
static wxString ToDisplayString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, uses the user's locale's decimal separator.
Definition: Internat.cpp:148
static wxCharBuffer mFilename
Definition: Internat.h:90
static wxChar GetDecimalSeparator()
Get the decimal separator for the current locale.
Definition: Internat.cpp:116