MCPcopy Create free account
hub / github.com/ReadyTalk/avian / copyAndEscape

Function copyAndEscape

classpath/java-lang.cpp:341–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341void copyAndEscape(char** dest, const char* src, size_t length)
342{
343 char* destp = *dest;
344 const char* end = src + length;
345
346 if (length != 0 && !needsEscape(src, length)) {
347 for (const char* ptr = src; ptr < end; ptr++) {
348 *(destp++) = *ptr;
349 }
350 } else {
351 *(destp++) = '"';
352
353 for (const char* ptr = src;; ptr++) {
354 unsigned numBackslashes = 0;
355
356 while (ptr < end && *ptr == '\\') {
357 ptr++;
358 numBackslashes++;
359 }
360
361 if (ptr == end) {
362 appendN(&destp, '\\', 2 * numBackslashes);
363 break;
364 } else if (*ptr == '"') {
365 appendN(&destp, '\\', 2 * numBackslashes + 1);
366 *(destp++) = *ptr;
367 } else {
368 appendN(&destp, '\\', numBackslashes);
369 *(destp++) = *ptr;
370 }
371 }
372
373 *(destp++) = '"';
374 }
375
376 *dest = destp;
377}
378
379extern "C" JNIEXPORT void JNICALL
380 Java_java_lang_Runtime_exec(JNIEnv* e,

Callers 1

Calls 2

needsEscapeFunction · 0.85
appendNFunction · 0.85

Tested by

no test coverage detected