Jump to content

UniCreateUconvObject: Difference between revisions

From EDM2
Ak120 (talk | contribs)
No edit summary
Ak120 (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== UniCreateUconvObject ==
Creates and initializes the conversion object.
; UniCreateUconvObject(cpName, uconvObj) : Creates and initializes the conversion object.
 
== Syntax ==
UniCreateUconvObject(cpName, uconvObj)  


=== Parameters ===
=== Parameters ===
; cpName - [[OS2 API:DataType:UniChar|UniChar]] - input : Name of the UCS conversion.
;cpName - [[UniChar]] - input : Name of the UCS conversion.
; uconvObj - [[OS2 API:DataType:UconvObject|UconvObject]] - output : The conversion object returned.
;uconvObj - [[UconvObject]] - output : The conversion object returned.


=== Constants ===
=== Constants ===
Line 11: Line 13:
=== Returns ===
=== Returns ===
An integer with values of:
An integer with values of:
* [[OS2 API:Unicode:error#ULS_INVALID|ULS_INVALID]]
* [[Unicode Errors#ULS_INVALID|ULS_INVALID]]
* [[OS2 API:Unicode:error#ULS_MAXFILESPERPROC|ULS_MAXFILESPERPROC]]
* [[Unicode Errors#ULS_MAXFILESPERPROC|ULS_MAXFILESPERPROC]]
* [[OS2 API:Unicode:error#ULS_MAXFILES|ULS_MAXFILES]]
* [[Unicode Errors#ULS_MAXFILES|ULS_MAXFILES]]
* [[OS2 API:Unicode:error#ULS_NOMEMORY|ULS_NOMEMORY]]
* [[Unicode Errors#ULS_NOMEMORY|ULS_NOMEMORY]]
* [[OS2 API:Unicode:error#ULS_SUCCESS|ULS_SUCCESS]]
* [[Unicode Errors#ULS_SUCCESS|ULS_SUCCESS]]
 
=== Module ===
 
=== Define (C/C++) ===
 
=== Export name/Ordinal ===


=== Calling conversion ===
=== Calling Convention ===
[[Cdecl32]]
[[Cdecl32]]


=== Example Code ===
=== Example Code ===
<code>
  character  in = "C:\SOMEPATH\FILE.TXT";
  character  in = "C:\SOMEPATH\FILE.TXT";
   
   
  size_t      cpNameLen = 12;
  size_t      cpNameLen = 12;
  [[OS2 API:DataType:ULONG|ULONG]]       codePage;
  ULONG      codePage;
  [[OS2 API:DataType:ULONG|ULONG]]       cpLen;    // length set by [[OS2 API:DosQueryCp|DosQueryCp]]
  ULONG      cpLen;    // length set by DosQueryCp
  [[OS2 API:DataType:UniChar|UniChar]]     cpName,    // length of cpNameLen
  UniChar    cpName,    // length of cpNameLen
             tempPath;  // length of CCHMAXPATH
             tempPath;  // length of CCHMAXPATH
  [[OS2 API:DataType:UconvObject|UconvObject]] uconvObj;
  UconvObject uconvObj;
  character  out;      // allocate to CCHMAXPATH
  character  out;      // allocate to CCHMAXPATH
  integer    rc;
  integer    rc;
 
  rc = DosQueryCp(size of ULONG, codePage, cpLen);
  rc = DosQueryCp(size of ULONG, codePage, cpLen);
 
  /* determine string for the conversion of codePage */
  /* determine string for the conversion of codePage */
  rc = UniMapCpToUcsCp(codePage, cpName, cpNameLen);
  rc = UniMapCpToUcsCp(codePage, cpName, cpNameLen);
Line 45: Line 42:
  rc = UniStrToUcs(uconv, tempPath, in, CCHMAXPATH);
  rc = UniStrToUcs(uconv, tempPath, in, CCHMAXPATH);
  rc = UniFreeUconvObject(uconvObj);
  rc = UniFreeUconvObject(uconvObj);
 
  /* conversion for current codepage that can be used for paths */
  /* conversion for current codepage that can be used for paths */
  rc = UniCreateUconvObject((UniChar pointer)L"@path=yes", uconvObj);
  rc = UniCreateUconvObject((UniChar pointer)L"@path=yes", uconvObj);
  rc = UniStrFromUcs(uconvObj, out, tempPath, CCHMAXPATH);
  rc = UniStrFromUcs(uconvObj, out, tempPath, CCHMAXPATH);
  rc = UniFreeUconvObject(uconvObj);
  rc = UniFreeUconvObject(uconvObj);
 
  /* use out - don't forget to de-allocate out when finished with it. */
  /* use out - don't forget to de-allocate out when finished with it. */
  /* error checking left out for brevity */
  /* error checking left out for brevity */
</code>
====Format====
<code>
#include <uconv.h>
int UniCreateUconvObject (
    UniChar    *cpname,        /* I  - UCS conversion specifier */
    UconvObject *uconv_object    /* O  - Conversion object handle */
)
</code>


=== Related Functions ===
=== Related Functions ===
[[OS2 API:UniFreeUconvObject|UniFreeUconvObject]]
*[[UniFreeUconvObject]]
[[OS2 API:UniQueryUconvObject|UniQueryUconvObject]]
*[[UniQueryUconvObject]]
[[OS2 API:UniSetUconvObject|UniSetUconvObject]]
*[[UniSetUconvObject]]


=== Notes ===
=== Notes ===
[[OS2 API:UniCreateUconvObject|UniCreateUconvObject]] returns a conversion object that describes a UCS-2 conversion between the code page specified by cpName and UCS.
'''UniCreateUconvObject''' returns a conversion object that describes a UCS-2 conversion between the code page specified by cpName and UCS.


A conversion object remains valid until it is freed with [[OS2_API:UniFreeUconvObject|UniFreeUconvObject]].
A conversion object remains valid until it is freed with [[UniFreeUconvObject]].


The cpName field is normally the Unicode string IBM- followed by the decimal number of the code page. Other names may be used. UCONV tables are kept in the \language\codepage directory on the boot drive.
The cpName field is normally the Unicode string IBM- followed by the decimal number of the code page. Other names may be used. UCONV tables are kept in the \language\codepage directory on the boot drive.


If the cpName parameter contains an empty string, [[OS2 API:UniCreateUconvObject|UniCreateUconvObject]] will create a conversion object based upon the value of the process codepage setting.
If the cpName parameter contains an empty string, '''UniCreateUconvObject''' will create a conversion object based upon the value of the process codepage setting.


[[OS2 API:UniCreateUconvObject|UniCreateUconvObject]] allows modifiers to be concatenated onto cpName, these modifiers change the default behavior of conversion objects. The caller can concatenate the following modifiers onto cpName.
'''UniCreateUconvObject''' allows modifiers to be concatenated onto cpName, these modifiers change the default behavior of conversion objects. The caller can concatenate the following modifiers onto cpName.


Modifiers are separated from the conversion object name by an at sign (@), and multiple modifiers are separated by a comma (,).  
Modifiers are separated from the conversion object name by an at sign (@), and multiple modifiers are separated by a comma (,).  


displaymask
;displaymask
 
:@map=data        All characters less than space are controls. (default)
                @map=data        All characters less than space are controls.
:@map=display    All characters less than space are glyphs.
                                (default)
:@map=cdra        Use IBM standard control conversion.
                @map=display    All characters less than space are glyphs.
:@map=clrf        CR and LF are controls, others are glyphs.
                @map=cdra        Use IBM standard control conversion.
;converttype
                @map=clrf        CR and LF are controls, others are glyphs.
:@path=yes        When performing Unicode conversions strings are assumed to contain pathnames. This setting is only applicable when converting to or from DBCS codepages. (default)
 
:@path=no        When performing Unicode conversions strings are assumed to contain non path data. This setting is only applicable when converting to or from DBCS codepages.
converttype
;endian
 
:@endian=Source:Target
                @path=yes        When performing Unicode conversions strings
:@endian=Both
                                are assumed to contain pathnames. This
:Source applies to UniUconvFromUcs; Target applies to UniUconvToUcs.  If only one endian is given, it applies to both source and target.
                                setting is only applicable when converting
:The endian type can be one of the following:
                                to or from DBCS codepages.
::system    Use system endian.
                                (default)
::big        Use big endian.
                @path=no        When performing Unicode conversions strings
::little    Use little endian. (default)
                                are assumed to contain non path data. This
:For example
                                setting is only applicable when converting
::@endian=little
                                to or from DBCS codepages.
::@endian=big:system
                               
;options
 
:@sub=yes          Perform substitutions when converting to and from Unicode.
endian
:@sub=no          Do not perform substitutions when converting to and from Unicode.
 
:@sub=to-ucs      Only perform substitutions when converting to Unicode.
                @endian=Source:Target
:@sub=from-ucs    Only perform substitutions when converting from Unicode. (default)
                @endian=Both
:@subchar=\xXX    Where XX is a hex number
                Source applies to UniUconvFromUcs; Target applies to
:@subchar=\DD      Where DD is a decimal number
                UniUconvToUcs.  If only one endian is given, it applies
::The substitution character attribute specifies which character the conversion object should use when there is no identical character for a given code element while converting from Unicode.
                to both source and target.
:@subuni=\xXX\xXX  Where XX is a hex number
                The endian type can be one of the following:
:@subuni=\xXXXX    Where XXXX is a hex number
                      system    Use system endian.
::The substitution character attribute specifies which character the conversion object should use when there is no identical character for a given code element while converting to Unicode.
                      big        Use big endian.
                      little    Use little endian.
                                (default)
                For example @endian=little
                            @endian=big:system
 
options
 
              @sub=yes          Perform substitutions when converting to and
                                from Unicode.
              @sub=no          Do not perform substitutions when converting
                                to and from Unicode.
              @sub=to-ucs      Only perform substitutions when converting to
                                Unicode.
              @sub=from-ucs    Only perform substitutions when converting from
                                Unicode.
                                (default)
              @subchar=\xXX    Where XX is a hex number
              @subchar=\DD      Where DD is a decimal number
                                The substitution character attribute specifies
                                which character the conversion object should
                                use when there is no identical character for
                                a given code element while converting from
                                Unicode.
              @subuni=\xXX\xXX  Where XX is a hex number
              @subuni=\xXXXX    Where XXXX is a hex number
                                The substitution character attribute specifies
                                which character the conversion object should
                                use when there is no identical character for
                                a given code element while converting to
                                Unicode.


Examples of typical usage:
Examples of typical usage:


IBM-942@path=yes,map=display
IBM-942@path=yes,map=display
 
This example creates a conversion object based upon an IBM-942
              This example creates a conversion object based upon an IBM-942
encoding. When conversions are performed all strings will be treated
              encoding. When conversions are performed all strings will be treated
as pathnames and all characters less than space will be considered
              as pathnames and all characters less than space will be considered
to be glyphs.
              to be glyphs.
 
@path=yes,sub=no
 
              This example creates a conversion object based upon the current
              process codepage setting. When conversions are performed all
              strings will be treated as pathnames and no substitutions will
              occur.


IBM-850@path=no,sub=yes
@path=yes,sub=no
This example creates a conversion object based upon the current
process codepage setting. When conversions are performed all
strings will be treated as pathnames and no substitutions will occur.


              This example creates a conversion object based upon an IBM-850
IBM-850@path=no,sub=yes
              encoding. When conversions are performed all strings will be  
This example creates a conversion object based upon an IBM-850
              treated as non pathnames and substitutions will occur when  
encoding. When conversions are performed all strings will be  
              converting to and from Unicode if necessary.
treated as non pathnames and substitutions will occur when  
converting to and from Unicode if necessary.


[[OS2 API:UniCreateUconvObject|UniCreateUconvObject]] returns a conversion object in uconvObj for use in subsequent calls to either [[OS2_API:UniUconvFromUcs|UniUconvFromUcs]] or [[OS2_API:UniUconvToUcs|UniUconvToUcs]].  
'''UniCreateUconvObject''' returns a conversion object in uconvObj for use in subsequent calls to either [[UniUconvFromUcs]] or [[UniUconvToUcs]].  


=== OS Version Introduced ===
=== OS Version Introduced ===
OS/2 Warp
OS/2 Warp


[[Category:The OS/2 API Project]]
[[Category:Uni]]

Latest revision as of 18:13, 4 December 2019

Creates and initializes the conversion object.

Syntax

UniCreateUconvObject(cpName, uconvObj) 

Parameters

cpName - UniChar - input
Name of the UCS conversion.
uconvObj - UconvObject - output
The conversion object returned.

Constants

None

Returns

An integer with values of:

Calling Convention

Cdecl32

Example Code

character   in = "C:\SOMEPATH\FILE.TXT";

size_t      cpNameLen = 12;
ULONG       codePage;
ULONG       cpLen;     // length set by DosQueryCp
UniChar     cpName,    // length of cpNameLen
            tempPath;  // length of CCHMAXPATH
UconvObject uconvObj;
character   out;       // allocate to CCHMAXPATH
integer     rc;

rc = DosQueryCp(size of ULONG, codePage, cpLen);

/* determine string for the conversion of codePage */
rc = UniMapCpToUcsCp(codePage, cpName, cpNameLen);
rc = UniCreateUconvObject(cpName, uconvObj);
rc = UniStrToUcs(uconv, tempPath, in, CCHMAXPATH);
rc = UniFreeUconvObject(uconvObj);

/* conversion for current codepage that can be used for paths */
rc = UniCreateUconvObject((UniChar pointer)L"@path=yes", uconvObj);
rc = UniStrFromUcs(uconvObj, out, tempPath, CCHMAXPATH);
rc = UniFreeUconvObject(uconvObj);

/* use out - don't forget to de-allocate out when finished with it. */
/* error checking left out for brevity */

Format

#include <uconv.h>

int UniCreateUconvObject (
    UniChar     *cpname,         /* I  - UCS conversion specifier */
    UconvObject *uconv_object    /* O  - Conversion object handle */
)

Related Functions

Notes

UniCreateUconvObject returns a conversion object that describes a UCS-2 conversion between the code page specified by cpName and UCS.

A conversion object remains valid until it is freed with UniFreeUconvObject.

The cpName field is normally the Unicode string IBM- followed by the decimal number of the code page. Other names may be used. UCONV tables are kept in the \language\codepage directory on the boot drive.

If the cpName parameter contains an empty string, UniCreateUconvObject will create a conversion object based upon the value of the process codepage setting.

UniCreateUconvObject allows modifiers to be concatenated onto cpName, these modifiers change the default behavior of conversion objects. The caller can concatenate the following modifiers onto cpName.

Modifiers are separated from the conversion object name by an at sign (@), and multiple modifiers are separated by a comma (,).

displaymask
@map=data All characters less than space are controls. (default)
@map=display All characters less than space are glyphs.
@map=cdra Use IBM standard control conversion.
@map=clrf CR and LF are controls, others are glyphs.
converttype
@path=yes When performing Unicode conversions strings are assumed to contain pathnames. This setting is only applicable when converting to or from DBCS codepages. (default)
@path=no When performing Unicode conversions strings are assumed to contain non path data. This setting is only applicable when converting to or from DBCS codepages.
endian
@endian=Source:Target
@endian=Both
Source applies to UniUconvFromUcs; Target applies to UniUconvToUcs. If only one endian is given, it applies to both source and target.
The endian type can be one of the following:
system Use system endian.
big Use big endian.
little Use little endian. (default)
For example
@endian=little
@endian=big:system
options
@sub=yes Perform substitutions when converting to and from Unicode.
@sub=no Do not perform substitutions when converting to and from Unicode.
@sub=to-ucs Only perform substitutions when converting to Unicode.
@sub=from-ucs Only perform substitutions when converting from Unicode. (default)
@subchar=\xXX Where XX is a hex number
@subchar=\DD Where DD is a decimal number
The substitution character attribute specifies which character the conversion object should use when there is no identical character for a given code element while converting from Unicode.
@subuni=\xXX\xXX Where XX is a hex number
@subuni=\xXXXX Where XXXX is a hex number
The substitution character attribute specifies which character the conversion object should use when there is no identical character for a given code element while converting to Unicode.

Examples of typical usage:

IBM-942@path=yes,map=display

This example creates a conversion object based upon an IBM-942 encoding. When conversions are performed all strings will be treated as pathnames and all characters less than space will be considered to be glyphs.

@path=yes,sub=no

This example creates a conversion object based upon the current process codepage setting. When conversions are performed all strings will be treated as pathnames and no substitutions will occur.

IBM-850@path=no,sub=yes

This example creates a conversion object based upon an IBM-850 encoding. When conversions are performed all strings will be treated as non pathnames and substitutions will occur when converting to and from Unicode if necessary.

UniCreateUconvObject returns a conversion object in uconvObj for use in subsequent calls to either UniUconvFromUcs or UniUconvToUcs.

OS Version Introduced

OS/2 Warp