Unicode and SBCS or DBCS Macro Programming

The following information applies for Unicode users only. When the code editor is running in UTF-8 mode (by default, vs.exe for Windows runs in this mode), buffers can contain either SBCS/DBCS data or UTF-8 data depending on how a buffer is loaded. To make it easier for macros to support these two buffer data formats, almost all macro functions accept and return UTF-8 strings. This allows most macros to automatically work. Macros that use or set column positions often do not work correctly for both buffer data formats. The solution is to call raw functions.

Example:

    // This will not work if the current buffer is an SBCS/DBCS buffer,
    // word is a UTF-8 string (that this example assumes), and word
    // contains characters above 127.
    p_col=p_col+length(word);
    // This will work.
    p_col=p_col+_rawLength(word);
    // This works too.
    word=_rawText(word);
    p_col=p_col+length(word);

Example:

    // This will not work if the current buffer is an SBCS/DBCS buffer and
    // the current line contains characters above 127.
    get_line(line);
 
    string=expand_tabs(line,p_col);
    // This works.
    get_line_raw(line);
 
    string=expand_tabs(line,p_col);
    // This works too, but is less efficient if all operations on line
    // can support raw data.
    get_line(line);
    string=expand_tabs(_rawText(line),p_col);

The _UTF8() macro function indicates if the code editor is in UTF-8 mode. The p_UTF8 property tells you whether the current buffer contains UTF-8 data. The p_encoding property indicates what format the buffer will be saved in by default.

Like typical programming languages (Java, C++), Slick-C® source files are code page dependant. Strings are converted from the current code page to UTF-8. This is important if you enter characters above 127. All of the macro functions and properties accept and return UTF-8. The Slick-C functions in the table below DO NOT accept or return UTF-8 data.

Function

Definition

_default_option(VSOPTIONZ_SPECIAL_CHAR_XLAT_TAB)

All other options for this function are UTF-8.

All seek functions: goto_point(), _QROffset(), _GoToROffset, _nrseek(), point(), and seek()

All seeking is done on raw data. Buffers need to be loaded in the same raw format so that seek functions work.

All _rawXXX() or XXX_raw() functions

Unlike the C API, the Slick-C functions get_text() and _expand_tabsc() return UTF-8 data.

The p_display_xlat Slick-C property DOES NOT accept or return UTF-8 data.

The following are the Slick-C raw functions:

The table below shows the raw functions that optionally support raw data.

Function

Description

pos()

When p_rawpos appended to options argument.

lastpos()

When p_rawpos appended to options argument.

upcase()

When p_UTF8 property given as second argument.

lowcase()

When p_UTF8 property given as second argument.

parse

When p_rawpos appended to options of search argument.

The following are the Slick-C new UTF-8 functions:

The following C API functions DO NOT accept or return UTF-8 data: