OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef BIN_UTILS_H_ | 5 #ifndef BIN_UTILS_H_ |
6 #define BIN_UTILS_H_ | 6 #define BIN_UTILS_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 SubSystem sub_system_; | 53 SubSystem sub_system_; |
54 int code_; | 54 int code_; |
55 char* message_; | 55 char* message_; |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(OSError); | 57 DISALLOW_COPY_AND_ASSIGN(OSError); |
58 }; | 58 }; |
59 | 59 |
| 60 |
60 class StringUtils { | 61 class StringUtils { |
61 public: | 62 public: |
62 // The following methods convert the argument if needed. The | 63 // The following methods convert the argument if needed. The |
63 // conversions are only needed on Windows. If the methods returns a | 64 // conversions are only needed on Windows. If the methods returns a |
64 // pointer that is different from the input pointer the returned | 65 // pointer that is different from the input pointer, the returned |
65 // pointer is allocated with malloc and should be freed using free. | 66 // pointer is allocated with malloc and should be freed using free. |
66 static const char* ConsoleStringToUtf8(const char* str); | 67 // |
67 static char* ConsoleStringToUtf8(char* str); | 68 // If the len argument is passed then that number of characters are |
68 static const char* Utf8ToConsoleString(const char* utf8); | 69 // converted. If len is -1, conversion will stop at the first NUL |
69 static char* Utf8ToConsoleString(char* utf8); | 70 // character. If result_len is not NUL, it is used to set the number |
70 static char* WideToUtf8(wchar_t* wide); | 71 // of characters in the result. |
71 static const char* WideToUtf8(const wchar_t* wide); | 72 // |
72 static wchar_t* Utf8ToWide(char* utf8); | 73 // These conversion functions are only implemented on Windows as the |
73 static const wchar_t* Utf8ToWide(const char* utf8); | 74 // Dart code only hit this path on Windows. |
| 75 static const char* ConsoleStringToUtf8(const char* str, |
| 76 intptr_t len = -1, |
| 77 intptr_t* result_len = NULL); |
| 78 static char* ConsoleStringToUtf8(char* str, |
| 79 intptr_t len = -1, |
| 80 intptr_t* result_len = NULL); |
| 81 static const char* Utf8ToConsoleString(const char* utf8, |
| 82 intptr_t len = -1, |
| 83 intptr_t* result_len = NULL); |
| 84 static char* Utf8ToConsoleString(char* utf8, |
| 85 intptr_t len = -1, |
| 86 intptr_t* result_len = NULL); |
74 }; | 87 }; |
75 | 88 |
| 89 |
76 class ShellUtils { | 90 class ShellUtils { |
77 public: | 91 public: |
78 // Get the arguments passed to the program as unicode strings. | 92 // Convert all the arguments to UTF8. On Windows, the arguments are |
79 // If GetUnicodeArgv returns a pointer that pointer has to be | 93 // encoded in the current code page and not UTF8. |
80 // deallocated with a call to FreeUnicodeArgv. | 94 // |
81 static wchar_t** GetUnicodeArgv(int* argc); | 95 // Returns true if the arguments are converted. In that case |
82 static void FreeUnicodeArgv(wchar_t** argv); | 96 // each of the arguments need to be deallocated using free. |
| 97 static bool GetUtf8Argv(int argc, char** argv); |
83 }; | 98 }; |
84 | 99 |
85 class TimerUtils { | 100 class TimerUtils { |
86 public: | 101 public: |
87 static int64_t GetCurrentTimeMicros(); | 102 static int64_t GetCurrentTimeMicros(); |
88 static int64_t GetCurrentTimeMilliseconds(); | 103 static int64_t GetCurrentTimeMilliseconds(); |
89 static void Sleep(int64_t millis); | 104 static void Sleep(int64_t millis); |
90 }; | 105 }; |
91 | 106 |
92 } // namespace bin | 107 } // namespace bin |
93 } // namespace dart | 108 } // namespace dart |
94 | 109 |
95 #endif // BIN_UTILS_H_ | 110 #endif // BIN_UTILS_H_ |
OLD | NEW |