Funcion en C++ a veces retorna string vacio?

No conozco mucho el lenguaje c++, necesito para un script una función que me sanee los inputs, y esta es la que me pasaron. La pruebo a veces funciona pero a veces retorna un string vacío. ¿Alguien me podría ayudar?
    char* sanitize(std::string input) {
        std::string new_string = std::regex_replace(input,std::regex{"'"},"´");
        new_string = std::regex_replace(new_string, std::regex{'"'},"´´");
        new_string = std::regex_replace(new_string, std::regex(R"(\\)"), R"()");
        new_string = std::regex_replace(new_string, std::regex{'<'},"");
         new_string = std::regex_replace(new_string, std::regex{'>'},"");
         new_string = std::regex_replace(new_string, std::regex{'-'},"");
        char* buffer = (char*)malloc(new_string.length());
        strcpy(buffer,new_string.c_str());
        return buffer;
    }

1 Respuesta

Respuesta

I. Hola Alfredo, no puedo atenderle debido a mi desconocimiento ni fuí capaz de encontrar información del todo válida o que no haya podido ver usted mismo Googleando, pero si lo desea y fuese necesario podría ponerle en contacto con varios programadores de la comunidad que sí podrán atenderle.

Con todo, deseaba trasladarle las siguientes páginas con información porque pienso que varias sí parecen abordar esta incidencia de primera mano y si dispusiera de tiempo podrían darle resultado.

Le ruego me disculpe todas las molestias de lectura y la manera de responderle.

Ánimo. Feliz año nuevo.


https://www.reddit.com/r/cprogramming/comments/1d9df82/string_variable_unexpectedly_becomes_an_empty/?tl=es-419

https://cplusplus-com.translate.goog/forum/general/44832/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://www.reddit.com/r/cpp_questions/comments/191w3d9/why_does_c_leave_nonvoid_functions_missing_return/

https://forum-pjrc-com.translate.goog/index.php?threads/class-string-bug-c_str-method-return-a-null-pointer.63842/&_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://tfetimes-com.translate.goog/c-empty-string/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://stackoverflow.com/questions/39006506/c-str-returns-empty-string/39006531#39006531

https://stackoverflow.com/questions/60702099/why-is-my-function-returning-an-empty-string

https://cplusplus-com.translate.goog/forum/beginner/122615/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://www.reddit.com/r/cpp_questions/comments/1adzyj9/empty_string_initialization/

https://es.stackoverflow.com/questions/174908/como-valido-un-string-vacio

https://www.luisllamas.es/cpp-retorno-funciones/

https://www.reddit.com/r/learnprogramming/comments/17td6b2/function_returning_empty_when_calling_function/?tl=es-419

https://stackoverflow.com/questions/55940308/the-function-returns-empty-string

https://www.quora.com/How-do-I-check-if-a-string-is-empty-in-C

https://forum-qt-io.translate.goog/topic/59448/solved-qstring-at-debug-vc-rt-error-if-string-empty-qt-5-5-0?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc&_x_tr_hist=true 

https://es.stackoverflow.com/questions/490165/porque-parece-como-que-estoy-pasando-un-string-vacio-en-mi-funcion

https://www.reddit.com/r/cpp_questions/comments/1adzyj9/empty_string_initialization/?tl=es-es

https://www.mathworks.com/matlabcentral/answers/378004-why-is-an-empty-string-not-empty-isempty-returns-true-but-isempty-returns-false

https://stackoverflow.com/questions/29190042/why-is-the-function-returning-an-empty-string

https://softwareengineering-stackexchange-com.translate.goog/questions/120355/is-it-better-to-return-null-or-empty-values-from-functions-methods-where-the-ret?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://c--for--dummies-com.translate.goog/blog/?p=2641&_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://www-cs-fsu-edu.translate.goog/~cop3014p/lectures/ch7/index.html?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://www-geeksforgeeks-org.translate.goog/cpp/std-string-empty-in-cpp/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://www.youtube.com/watch?v=qkJENfBg1z4

https://forum.arduino.cc/t/string-is-empty-after-being-passed-to-a-function/1309839

https://documentation.help/C-Cpp-Reference/empty.html

https://gist-github-com.translate.goog/ybakos/9078101?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://ccia.ugr.es/~edatos/material/strings.html 

https://cplusplus-com.translate.goog/forum/general/90164/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://www.quora.com/How-do-you-return-a-string-from-a-function-in-C-if-you-dont-want-to-store-it-into-anything-specific-just-return-it-directly-at-the-end-of-your-functions-code-body

https://www.sololearn.com/en/Discuss/1405064/empty-function-in-c

https://forums.unrealengine.com/t/c-http-response-returns-nothing-in-a-function-call-of-a-function/719781

https://www-w3schools-com.translate.goog/cpp/ref_string_empty.asp?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=es&_x_tr_pto=sc

https://julioecheverri.wordpress.com/2014/07/23/el-tipo-string-y-sus-metodos-mas-importantes-en-c/ 

https://stackoverflow.com/questions/41253758/google-script-function-returns-blank-output

https://es.stackoverflow.com/questions/587902/validar-si-un-string-o-int-se-encuentra-vaci%C3%B3-c 

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas