CSetRef()

CSetRef()

Determine return value of reference sensitive CT3 string functions

Syntax

      CSetRef( [<lNewSwitch>] ) -> lOldSwitch

Arguments

[<lNewSwitch>] .T. -> suppress return value .F. -> do not suppress return value

Returns

lOldSwitch old (if lNewSwitch is a logical value) or current state of the switch

Description

Within the CT3 functions, the following functions do not change the length of a string passed as parameter while transforming this string:

ADDASCII() BLANK() CHARADD() CHARAND() CHARMIRR() CHARNOT() CHAROR() CHARRELREP() CHARREPL() CHARSORT() CHARSWAP() CHARXOR() CRYPT() JUSTLEFT() JUSTRIGHT() POSCHAR() POSREPL() RANGEREPL() REPLALL() REPLLEFT() REPLRIGHT() TOKENLOWER() TOKENUPPER() WORDREPL() WORDSWAP()

Thus, these functions allow to pass the string by reference [@] to the function so that it may not be necessary to return the transformed string. By calling CSetRef (.T.), the above mentioned functions return the value .F. instead of the transformed string if the string is passed by reference to the function. The switch is turned off (.F.) by default.

Compliance

This function is fully CT3 compatible.

Platforms

All

Files

Source is ctstr.c, library is ct3.

Seealso

ADDASCII(), BLANK(), CHARADD(), CHARAND(), CHARMIRR(), CHARNOT(), CHAROR(), CHARRELREP(), CHARREPL(), CHARSORT(), CHARSWAP(), CHARXOR(), CRYPT(), JUSTLEFT(), JUSTRIGHT(), POSCHAR(), POSREPL(), RANGEREPL(), REPLALL(), REPLLEFT(), REPLRIGHT(), TOKENLOWER(), TOKENUPPER(), WORDREPL(), WORDSWAP()

CharXOR()

CHARXOR()

Combine corresponding ASCII value of two strings with bitwise XOR

Syntax

      CHARXOR( <[@]cString1>, <cString2> ) --> cXOrString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cXOrString> string with bitwise XOR combined ASCII values

Description

The CHARXOR() function constructs a new string from the two strings passed as parameters. To do this, it combines the ASCII values of the corresponding characters of both strings with a bitwise XOR-operation and places a character in the resulting string whose ASCII value equals to the result of that operation. If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      // easy encryption
      ? charxor( "This is top secret !", "My Password" ) // --> <encrypted sentence>

Tests

      charxor( charxor( "This is top secret !", "My Password" ), "My Password" ) == "This is top secret !"

Compliance

CHARXOR() is compatible with CT3’s CHARXOR().

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARNOT(), CHARAND(), CHAROR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharSub()

CHARSUB()

Subtracts corresponding ASCII value of two strings

Syntax

      CHARSUB( <[@]cString1>, <cString2>) --> cSubString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cSubString> string with subtracted ASCII values

Description

The CHARSUB() function constructs a new string from the two strings passed as parameters. To do this, it subtracts the ASCII values of the corresponding characters of both strings and places a character in the resulting string whose ASCII value equals to that difference (modulo 256). If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      ? charsub( "012345678", Chr( 1 ) ) // --> "/01234567"
      ? charsub( "123456789", Chr( 255 ) ) // --> "23456789:"
      ? charsub( "9999", Chr( 0 ) + Chr( 1 ) + Chr( 2 ) + Chr( 3 ) ) // --> "9876"

Tests

      charsub( "123456789", Chr( 1 ) ) == "012345678"
      charsub( "123456789", Chr( 1 ) + Chr( 2 ) ) == "002244668"
      charsub( "012345678", Chr( 255 ) ) == "123456789"
      charsub( "012345678", Chr( 255 ) + Chr( 254 ) ) == "133557799"

Compliance

CHARSUB() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARAND(), CHARNOT(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharSHR()

CHARSHR()

Process each character in a string with bitwise SHIFT RIGHT operation

Syntax

      CHARSHR( <[@]cString>, <nBitsToSHR> ) --> cSHRString

Arguments

<[@]cString> string to be processed

<nBitsToSHR> number of bit positions to be shifted to the right

Returns

<cSHRString> string with bitwise shifted right characters

Description

The CHARSHR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT RIGHT (SHR) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLR() function instead. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charshr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(0)+Chr(0)+Chr(0)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Tests

      charshr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 ) 
      == Chr(0)+Chr(0)+Chr(0)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Compliance

CHARSHR() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARRLL(), CHARRLR(), CSETREF()

CharSHL()

CHARSHL()

Process each character in a string with bitwise SHIFT LEFT operation

Syntax

      CHARSHL( <[@]cString>, <nBitsToSHL> ) --> cSHLString

Arguments

<[@]cString> string to be processed

<nBitsToSHL> number of bit positions to be shifted to the left

Returns

<cSHLString> string with bitwise shifted left characters

Description

The CHARSHL() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT LEFT (SHL) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLL() function instead. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charshl( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(0)+Chr(0)+Chr(0)

Tests

      charshl( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
       == Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(0)+Chr(0)+Chr(0)

Compliance

CHARSHL() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharRLR()

CHARRLR()

Process each character in a string with bitwise ROLL RIGHT operation

Syntax

      CHARRLR( <[@]cString>, <nBitsToRLR> ) --> cRLRString

Arguments

<[@]cString> string to be processed

<nBitsToRLR> number of bit positions to be rolled to the right

Returns

<cRLRString> string with bitwise rolled right characters

Description

The CHARRLR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise ROLL RIGHT (RLR) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that, in contrast to CHARSHR(), bits rolled out on the right are put in again on the left. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charrlr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Tests

      charrlr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
       == Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Compliance

CHARRLR() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARSHR(), CHARRLL(), CSETREF()

CharRLL()

CHARRLL()

Process each character in a string with bitwise ROLL LEFT operation

Syntax

      CHARRLL( <[@]cString>, <nBitsToRLL> ) --> cRLLString

Arguments

<[@]cString> string to be processed

<nBitsToRLL> number of bit positions to be rolled to the left

Returns

<cRLLString> string with bitwise rolled left characters

Description

The CHARRLL() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise ROLL LEFT (RLL) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that, in contrast to CHARSHL(), bits rolled out on the left are put in again on the right. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charrll( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)

Tests

      charrll( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 ) 
        == Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)

Compliance

CHARRLL() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARSHR(), CHARRLR(), CSETREF()