Jump to content

UniStrFromUcs: Difference between revisions

From EDM2
m corrected variable name
Ak120 (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== UniStrFromUcs ==
Convert a UCS string to a code page string.
; UniStrFromUcs(uconvObj, outBuffer, ucsString, outBufferLen) : Convert a UCS string to a code page string.
 
=== Syntax ===
UniStrFromUcs(uconvObj, outBuffer, ucsString, outBufferLen);


=== Parameters ===
=== Parameters ===
; uconvObj - [[OS2 API:DataType:UconvObject|UconvObject]] - input : The conversion object created from [[OS2_API:UniCreateUconvObject|UniCreateUconvObject]].
;uconvObj - [[UconvObject]] - input : The conversion object created from [[UniCreateUconvObject]].
; outBuffer - [[OS2 API:DataType:CHAR|CHAR]] - input : The output buffer to hold code page.
;outBuffer - [[CHAR]] - output : The output buffer to hold code page.
; ucsString - [[OS2 API:DataType:UniChar|UniChar]] - input : Null terminated Unicode string.
;ucsString - [[UniChar]] - input : Null terminated Unicode string.
; outBufferLen - (int) - input/output : The output buffer's length, in bytes.
;outBufferLen - (int) - input/output : The output buffer's length, in bytes.
 
=== Constants ===
None


=== Returns ===
=== Returns ===
An integer with values of:
An integer with values of:
* [[OS2 API:Unicode:error#ULS_BADOBJECT|ULS_BADOBJECT]]
* [[Unicode Errors#ULS_BADOBJECT|ULS_BADOBJECT]]
* [[OS2 API:Unicode:error#ULS_BUFFERFULL|ULS_BUFFERFULL]]
* [[Unicode Errors#ULS_BUFFERFULL|ULS_BUFFERFULL]]
* [[OS2 API:Unicode:error#ULS_ILLEGALSEQUENCE|ULS_ILLEGALSEQUENCE]]
* [[Unicode Errors#ULS_ILLEGALSEQUENCE|ULS_ILLEGALSEQUENCE]]
* [[OS2 API:Unicode:error#ULS_SUCCESS|ULS_SUCCESS]]
* [[Unicode Errors#ULS_SUCCESS|ULS_SUCCESS]]


=== Module ===
=== Calling Convention ===
[[Cdecl32]]


=== Define (C/C++) ===
=== Example Code ===
<pre>
character  in = "C:\SOMEPATH\FILE.TXT";
size_t      unicodeBuffLen = 12;
[[ULONG]]  codePage;
ULONG      cpLen;      // length set by [[DosQueryCp]]
[[UniChar]] unicodeBuff, // length of unicodeBuffLen
            ucsString;  // length of CCHMAXPATH
[[UconvObject]] uconv;
character  outBuffer;  // allocate to CCHMAXPATH
integer    rc;


=== Export name/Ordinal ===
rc = DosQueryCp(size of ULONG, codePage, cpLen);


=== Calling conversion ===
/* determine string for the conversion of codePage */
[[Cdecl32]]
rc = UniMapCpToUcsCp(codePage, unicodeBuff, unicodeBuffLen);
rc = UniCreateUconvObject(unicodeBuff, uconvObj);
rc = UniStrToUcs(uconvObj, ucsString, in, CCHMAXPATH);
rc = UniFreeUconvObject(uconvObj);


=== Example Code ===
  /* conversion for current codepage that can be used for paths */
  [[OS2 API:DataType:UconvObject|UconvObject]] uconvObj;
  rc = UniCreateUconvObject((UniChar pointer)L"@path=yes", uconvObj);
[[OS2 API:DataType:CHAR|CHAR]]*       outBuffer;
  rc = UniStrFromUcs(uconvObj, outBuffer, ucsString, CCHMAXPATH);
  [[OS2 API:DataType:UniChar|UniChar]]    ucsString;
  rc = UniFreeUconvObject(uconvObj);
integer    outBufferLen;
[[OS2 API:DataType:APIRET|APIRET]]      rc;
...
  rc = UniStrFromUcs(uconvObj, outBuffer, ucsString, outBufferLen);
  ...


=== Related Functions ===
/* use outBuffer - don't forget to de-allocate outBuffer when finished with it. */
[[OS2 API:UniUconvFromUcs|UniconvFromUcs]]
/* error checking left out for brevity */
[[OS2 API:UniUconvToUcs|UniconvToUcs]]
</pre>
[[OS2 API:UniStrToUcs|UniStrToUcs]]


=== Notes ===
=== Notes ===
The sequence of code elements in ucsString is converted into a sequence of code page characters to outBuffer. The code page was set by [[OS2_API:UniCreateUconvObject|UniCreateUnconvObject]] call in the [[OS2_API:DataType:UconvObject|UconvObject]].
The sequence of code elements in ucsString is converted into a sequence of code page characters to outBuffer. The code page was set by [[UniCreateUconvObject]] call in the [[UconvObject]].


If the outBuffer isn't large enough, conversion ends on the byte previous to any buffer overflow.  outBuffer is updated truncating the point of failure to the end and updating the outBufferLen to indicate the number of successfully converted bytes.
If the outBuffer isn't large enough, conversion ends on the byte previous to any buffer overflow.  outBuffer is updated truncating the point of failure to the end and updating the outBufferLen to indicate the number of successfully converted bytes.


If [[OS2_API:UniStrFromUcs|UniStrFromUcs]] contains a code sequence in ucsString that is legal with no corresponding character in the target codepage this function will replace it with a predefined substituted character.
If '''UniStrFromUcs''' contains a code sequence in ucsString that is legal with no corresponding character in the target codepage this function will replace it with a predefined substituted character.


=== OS Version Introduced ===
=== OS Version Introduced ===
OS/2 Warp
*OS/2 Warp
 
=== Related Functions ===
*UniConvFromUcs
*UniConvToUcs
*[[UniStrToUcs]]
 
[[Category:Uni]]

Latest revision as of 18:03, 4 December 2019

Convert a UCS string to a code page string.

Syntax

UniStrFromUcs(uconvObj, outBuffer, ucsString, outBufferLen);

Parameters

uconvObj - UconvObject - input
The conversion object created from UniCreateUconvObject.
outBuffer - CHAR - output
The output buffer to hold code page.
ucsString - UniChar - input
Null terminated Unicode string.
outBufferLen - (int) - input/output
The output buffer's length, in bytes.

Returns

An integer with values of:

Calling Convention

Cdecl32

Example Code

 character   in = "C:\SOMEPATH\FILE.TXT";
 
 size_t      unicodeBuffLen = 12;
 [[ULONG]]   codePage;
 ULONG       cpLen;       // length set by [[DosQueryCp]]
 [[UniChar]] unicodeBuff, // length of unicodeBuffLen
             ucsString;   // length of CCHMAXPATH
 [[UconvObject]] uconv;
 character   outBuffer;   // allocate to CCHMAXPATH
 integer     rc;

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

 /* determine string for the conversion of codePage */
 rc = UniMapCpToUcsCp(codePage, unicodeBuff, unicodeBuffLen);
 rc = UniCreateUconvObject(unicodeBuff, uconvObj);
 rc = UniStrToUcs(uconvObj, ucsString, 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, outBuffer, ucsString, CCHMAXPATH);
 rc = UniFreeUconvObject(uconvObj);

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

Notes

The sequence of code elements in ucsString is converted into a sequence of code page characters to outBuffer. The code page was set by UniCreateUconvObject call in the UconvObject.

If the outBuffer isn't large enough, conversion ends on the byte previous to any buffer overflow. outBuffer is updated truncating the point of failure to the end and updating the outBufferLen to indicate the number of successfully converted bytes.

If UniStrFromUcs contains a code sequence in ucsString that is legal with no corresponding character in the target codepage this function will replace it with a predefined substituted character.

OS Version Introduced

  • OS/2 Warp

Related Functions