SOL9 Sample: URLEncDec

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * URLEncDec.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// 2012/03/10 Updated.

#include <sol\URLEncoder.h>
#include <sol\URLDecoder.h>
#include <sol/Locale.h>

void _tmain(int argc, TCHAR** argv)
{
  //2012/03/10
  Locale locale;

  const char* string = 
    "<html>\n"
    "<body>\n"
    "<h1>URLEncoder/URLDecoder test!</h1>\n"
    "<h2>1234567890</h2>\n"
    "<h3>ABCDEFGHIJKLMNOPQRSTUVWXYZ</h3>\n"
    "<h3>abcdefghijklmnopqrstuvwxyz</h3>\n"
    "<h3>!\"#$%&'()=~|0\\`{[]}+*<>?/_</h3>\n"
    "</body>\n"
    "</html>\n";

  printf("String=[%s]\n", string);

  // Encoding
  URLEncoder encoder;
  char* encoded = encoder.encode(string);
  printf("Encoded1=[%s]\n", encoded);

  String enc;
  encoder.encode(string, enc);
  _tprintf(_T("Encoded2=[%s]\n"), (const TCHAR*)enc);

  // Decoding
  URLDecoder decoder;

  char* decoded = decoder.decode(encoded);

  printf("Decoded1=[%s]\n", decoded);
  String dec;
  decoder.decode(encoded, dec);

  _tprintf(_T("Decoded2=[%s]\n"), (const TCHAR*)dec);
  

  if (strcmp(string, decoded) ==0) {
    printf("OK. url-encode and url-decode created the same original string \n");
  } else {
    printf("Failed to url-encode or url-decode.\n");

  }
  delete [] encoded;
  delete [] decoded;

  //2012/03/10
  const String bstring = string;

  String bencoded = encoder.encode(bstring);
  _tprintf(_T("String Encoded = %s\n"), (const TCHAR*)bencoded);

  String bdecoded = decoder.decode(bencoded);
  _tprintf(_T("String Decoded = %s\n"), (const TCHAR*)bdecoded);

  const WString wstring = 
    L"<html>\n"
    L"<body>\n"
    L"<h1>WString URLEncoder/URLDecoder test!</h1>\n"
    L"<h2>こんにちは</h2>\n"      //Japanese text
    L"<h2>1234567890</h2>\n"

    L"<h3>ABCDEFGHIJKLMNOPQRSTUVWXYZ</h3>\n"
    L"<h3>abcdefghijklmnopqrstuvwxyz</h3>\n"
    L"<h3>!\"#$%&'()=~|0\\`{[]}+*<>?/_</h3>\n"
    L"<h3>これは日本語です</h3>\n"      //Japanese text
    L"</body>\n"
    L"</html>\n";;

  WString wencoded = encoder.encode(wstring);
  printf("WString Encoded = %S\n", (const wchar_t*)wencoded);

  WString wdecoded = decoder.decode(wencoded);
  printf("WString Decoded = %S\n", (const wchar_t*)wdecoded);

}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.