User:Free Portal/Sandbox/LSL Library/SKUTF8ToUnicode

From Second Life Wiki
Jump to navigation Jump to search

Sera korea Viewer Hangul item name decode script.

SKUTF8ToUnicode

<lsl>// ---------------------------------------------------------------------------- // SKUTF8ToUnicode // @author Free Portal (thedig@hyouk.net) // ---------------------------------------------------------------------------- // Dec 20, 2009 v1.0 - SKUTF8ToUnicode, orig code // ----------------------------------------------------------------------------

// ---------------------------------------------------------------------------- // Global Variables: // ---------------------------------------------------------------------------- integer handle;

// ---------------------------------------------------------------------------- // User Defined Functions // ----------------------------------------------------------------------------

// ---------------------------------------------------------------------------- // searchReplace // ---------------------------------------------------------------------------- // @param: // string input // string old // string new // // @return: // string // // @comment: // search and replace word // ---------------------------------------------------------------------------- string searchReplace(string input, string old, string new) {

  return llDumpList2String(llParseString2List(input, [old], []), new);

}

// ---------------------------------------------------------------------------- // insertString // ---------------------------------------------------------------------------- // @param: // string source // integer shift // string word // // @return: // string // // @comment: // insert word // ---------------------------------------------------------------------------- string insertString(string source, integer shift, string word) {

   string  tmp = source;
   integer index;
   for (index = 0; index < llStringLength(source) +
       (llStringLength(source) / shift); index+=shift+1)
       tmp = llInsertString(tmp, index, word);
   
   return source = tmp;

}

// ---------------------------------------------------------------------------- // SKUTF8ToUnicode // ---------------------------------------------------------------------------- // @param: // string input // // @return: // string // // @comment: // utf-8 hex to unicode // ---------------------------------------------------------------------------- string SKUTF8ToUnicode(string input) {

   return llUnescapeURL(
               insertString(searchReplace(input, "_SKUTF8_", ""), 2, "%")
           );

}

// ---------------------------------------------------------------------------- // Main Script // ---------------------------------------------------------------------------- default {

   state_entry() {
       handle = llListen(0x00, "", NULL_KEY, "");
       llListenControl(handle, FALSE);
   }
   touch_start(integer total_number) {
       llListenControl(handle, TRUE);
       llSay (0x00, "Input Sera Korea Viewer item name.");
   }
   
   listen(integer channel, string name, key id, string message) {
       if (!llSubStringIndex(message, "_SKUTF8_")) {
           llSay (0x00, "Item Name " + SKUTF8ToUnicode(message));
           llListenControl(handle, FALSE);
       }
   }

} </lsl>