Whitebeam Object Definition

Site Map
 
Home
 
Application Guide
Reference
  Installation
  Configuration
  XML Markup
  JavaScript Classes
  ROM
  Templates
  Environment
  Dev Process
  Tools
  External Links
  Example libraries
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

Whitebeam Object Definition

Method Description

WbString.fromUTF8()

Extract a Javascript string from a UTF-8 encoded string

See Also

WbString.toUTF8()   

Syntax

WbString = WbString.fromUTF8(input_string)

Parameters

The 'WbString.fromUTF8' method takes 1 parameter:

Name Type/Value Range/Length Description
input_stringstring  Required. String to be decoded

Results

The 'WbString.fromUTF8' method returns WbString:

Type/Value Range/Length Description
WbString   Returns a WbString instance containing the decoded characters

Remarks

Decode a string from a valid UTF-8 form

Note: This is a method method on WbString and so is invoked as WbString.fromUTF8(str);

Characters received from a web-browser or other remote system are often encoded in UTF-8. The way the Whitebeam XML system works with the Spidermonkey engine means that the UTF-8 characters will be simply expanded into 16 bit characters, but not correctly decoded.

For example, the two byte sequence C2 A3 is the correct UTF-8 encoding for the British £ symbol. by default this will appear in Javascript as two 16 bit characters 00C2 00A3, not the correctly decoded single 16 bit character 00A3.

WbString.fromUTF8 will take the initial string and correctly reconstruct the character sequence in Javascript.

Generally AJAX exchanges will use the UTF-8 encoding. It is important to know what encoding is in use for a received string before simply calling fromUTF8. If the string is, for example, LATIN-1, then the decoded string will not be as you expect!

The method returns a new WbString instance that to all intents and purposes can be treated as a standard Javascript string object.

Example

The following code takes a test string from the remore client and correcty builds a Javascript string:

             var params = rb.page.formdata();
             if (params.text!=null) {
               // params.text might contain two 16 bit characters now, eg 00C2 00A3

               params.text = WbString.fromUTF8(params.text);
               // and now correctly contains the single character code 00A3.
             }
         
Whitebeam release 1.3.36
(loadtime : 10ms)