Доброе время суток!
Подскажите плиз,
какой существует аналог метода в ТС который реализован в LR web_convert_param("InputParam", "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST); ?

Конвертация ascii кода в URL-encoding ?
Автор KRULIT, 18 янв 2011 12:57
Сообщений в теме: 4
#1
Отправлено 18 января 2011 - 12:57
#2
Отправлено 19 января 2011 - 09:49
Доброе время суток!
Подскажите плиз,
какой существует аналог метода в ТС который реализован в LR web_convert_param("InputParam", "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST); ?
А что делает функция web_convert_param ?
Приведите пример.
#3
Отправлено 19 января 2011 - 11:16
А что делает функция web_convert_param ?
Приведите пример.
Конвертирует строку "Бланк+со+вписываемыми+строками+(консолидированный)" в строку
"%D0%91%D0%BB%D0%B0%D0%BD%D0%BA+%D1%81%D0%BE+%D0%B2%D0%BF%D0%B8%D1%81%D1%8B%D0%B2%D0%B0%D0%B5%D0%BC%D1%8B%D0%BC%D0%B8+%D1%81%D1%82%D1%80%D0%BE%D0%BA%D0%B0%D0%BC%D0%B8+(%D0%BA%D0%BE%D0%BD%D1%81%D0%BE%D0%BB%D0%B8%D0%B4%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D1%8B%D0%B9)"
#4
Отправлено 19 января 2011 - 12:02
НАсколько мне известно - нет.
Надо писать самому.
Надо писать самому.
#5
Отправлено 19 января 2011 - 12:26
Согласен, такого конвертора нет.
Нашел такой вариант кода для LR. Годится для TC
Нашел такой вариант кода для LR. Годится для TC
EncodePlainToURL function. The logic is simple enough: If the current character is a digits or an alphabetic letter, then pass it "as is" Otherwise the current character is a special one. So, hex-code should be written in this case This is a code of EncodePlainToURL function: /* * EncodePlainToURL converts a plain text string to an URL-form string. * * Parameters: sIn - input string to be encoded to URL format * sOut - output buffer * Note: the size of "sOut" parameter should be at least equal to triple size * of "sIn" parameter plus one character(for end-terminator '\0') * * Author: Dmitry Motevich * * Examples: "a" -> "a" * "a b" -> "a%20b" * "a b_cc:\/c%" -> "a%20b%5Fcc%3A%2Fc%25" */ char *EncodePlainToURL(const char *sIn, char *sOut) { int i; char cCurChar; char sCurStr[4] = {0}; sOut[0] = '\0'; for (i = 0; cCurChar = sIn[i]; i++) { // if this is a digit or an alphabetic letter if (isdigit(cCurChar) || isalpha(cCurChar)) { // then write the current character "as is" sprintf(sCurStr, "%c", cCurChar); } else { // else convert it to hex-form. "_" -> "%5F" sprintf(sCurStr, "%%%X", cCurChar); } // append current item to the output string strcat(sOut, sCurStr); } return sOut; } The example of usage is: char sIn[] = "t es%d$ + eprst_"; char sOut[100]; lr_output_message("%s", EncodePlainToURL(sIn, sOut)); Execute the code, and see the result: The input string "t es%d$ + eprst_" was converted to "t%20es%25d%24%20%2B%20eprst%5F". Yeah! :) All special characters (including spaces) were converted to hex-code, i.e. to URL-format! Dmitry Motevich
Количество пользователей, читающих эту тему: 1
0 пользователей, 1 гостей, 0 анонимных