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 #include "vm/zone.h" | 5 #include "vm/zone.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/handles_impl.h" | 10 #include "vm/handles_impl.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 | 163 |
164 char* Zone::MakeCopyOfString(const char* str) { | 164 char* Zone::MakeCopyOfString(const char* str) { |
165 intptr_t len = strlen(str) + 1; // '\0'-terminated. | 165 intptr_t len = strlen(str) + 1; // '\0'-terminated. |
166 char* copy = Alloc<char>(len); | 166 char* copy = Alloc<char>(len); |
167 strncpy(copy, str, len); | 167 strncpy(copy, str, len); |
168 return copy; | 168 return copy; |
169 } | 169 } |
170 | 170 |
171 | 171 |
| 172 char* Zone::MakeCopyOfStringN(const char* str, intptr_t len) { |
| 173 ASSERT(len >= 0); |
| 174 for (intptr_t i = 0; i < len; i++) { |
| 175 if (str[i] == '\0') { |
| 176 len = i; |
| 177 break; |
| 178 } |
| 179 } |
| 180 char* copy = Alloc<char>(len + 1); // +1 for '\0' |
| 181 strncpy(copy, str, len); |
| 182 copy[len] = '\0'; |
| 183 return copy; |
| 184 } |
| 185 |
| 186 |
172 char* Zone::ConcatStrings(const char* a, const char* b, char join) { | 187 char* Zone::ConcatStrings(const char* a, const char* b, char join) { |
173 intptr_t a_len = (a == NULL) ? 0 : strlen(a); | 188 intptr_t a_len = (a == NULL) ? 0 : strlen(a); |
174 const intptr_t b_len = strlen(b) + 1; // '\0'-terminated. | 189 const intptr_t b_len = strlen(b) + 1; // '\0'-terminated. |
175 const intptr_t len = a_len + b_len; | 190 const intptr_t len = a_len + b_len; |
176 char* copy = Alloc<char>(len); | 191 char* copy = Alloc<char>(len); |
177 if (a_len > 0) { | 192 if (a_len > 0) { |
178 strncpy(copy, a, a_len); | 193 strncpy(copy, a, a_len); |
179 // Insert join character. | 194 // Insert join character. |
180 copy[a_len++] = join; | 195 copy[a_len++] = join; |
181 } | 196 } |
(...skipping 30 matching lines...) Expand all Loading... |
212 return buffer; | 227 return buffer; |
213 } | 228 } |
214 | 229 |
215 | 230 |
216 char* Zone::VPrint(const char* format, va_list args) { | 231 char* Zone::VPrint(const char* format, va_list args) { |
217 return OS::VSCreate(this, format, args); | 232 return OS::VSCreate(this, format, args); |
218 } | 233 } |
219 | 234 |
220 | 235 |
221 } // namespace dart | 236 } // namespace dart |
OLD | NEW |