Перейти к содержимому

Фотография

Конвертация ascii кода в URL-encoding ?


  • Авторизуйтесь для ответа в теме
Сообщений в теме: 4

#1 KRULIT

KRULIT

    Новый участник

  • Members
  • Pip
  • 47 сообщений
  • ФИО:Ковальчук Роман Львович
  • Город:Киев

Отправлено 18 января 2011 - 12:57

Доброе время суток!

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

#2 SergeyP

SergeyP

    Специалист

  • Members
  • PipPipPipPipPip
  • 651 сообщений
  • Город:Москва

Отправлено 19 января 2011 - 09:49

Доброе время суток!

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


А что делает функция web_convert_param ?
Приведите пример.
  • 0

#3 KRULIT

KRULIT

    Новый участник

  • Members
  • Pip
  • 47 сообщений
  • ФИО:Ковальчук Роман Львович
  • Город:Киев

Отправлено 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)"
  • 0

#4 VitalyD

VitalyD

    Опытный участник

  • Members
  • PipPipPipPip
  • 285 сообщений
  • Город:Санкт-Петербург

Отправлено 19 января 2011 - 12:02

НАсколько мне известно - нет.
Надо писать самому.


  • 0

#5 SergeyP

SergeyP

    Специалист

  • Members
  • PipPipPipPipPip
  • 651 сообщений
  • Город:Москва

Отправлено 19 января 2011 - 12:26

Согласен, такого конвертора нет.

Нашел такой вариант кода для 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


  • 0


Количество пользователей, читающих эту тему: 1

0 пользователей, 1 гостей, 0 анонимных