Table of contents
CSPICE_CMPRSS compresses a character string by truncating
occurrences of more than 'n' consecutive occurrences of a
specified character to 'n' occurrences.
Given:
delim the delimiter to be compressed out of the string.
help, delim
STRING = Scalar
This may be any ASCII character.
n the maximum number of consecutive occurrences of `delim' that
will be allowed to remain in the output string.
help, n
LONG = Scalar
input the input string.
help, input
STRING = Scalar
The routine allocates memory for the `output' string based on
the length of the `input' string. An `input' string with length
zero is an no-op.
the call:
cspice_cmprss, delim, n, input, output
returns:
output the output string.
help, output
STRING = Scalar
This is the input string with all occurrences of more than `n'
consecutive delimiters removed.
`output' may overwrite `input'.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Remove multiple occurrences of a character in different strings.
As example, compress the occurrences of '.' down to two periods
(..), three periods (...) or just one period (.). Also, as a
practical example, remove trailing, leading and embedded spaces
from an input string.
Example code begins here.
PRO cmprss_ex1
strings = [ 'ABC...DE.F...', $
'...........', $
'.. ..AB....CD' ]
;;
;; Compress multiple occurrences of '.'
;; in the strings array. Compress to
;; two periods...
;;
cspice_cmprss, '.', 2, strings[0], output
print, 'Input : `', strings[0], '`'
print, 'Output: `', output, '`'
print, ''
;;
;; ...three periods...
;;
cspice_cmprss, '.', 3, strings[1], output
print, 'Input : `', strings[1], '`'
print, 'Output: `', output, '`'
print, ''
;;
;; ...one period.
;;
cspice_cmprss, '.', 1, strings[2], output
print, 'Input : `', strings[2], '`'
print, 'Output: `', output, '`'
print, ''
;;
;; Use the call to remove trailing, leading, and
;; embedded spaces.
;;
cspice_cmprss, ' ', 0, ' Embe dde d -sp a c es ', output
print, 'Input : ', '` Embe dde d -sp a c es `'
print, 'Output: `', output, '`'
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Input : `ABC...DE.F...`
Output: `ABC..DE.F..`
Input : `...........`
Output: `...`
Input : `.. ..AB....CD`
Output: `. .AB.CD`
Input : ` Embe dde d -sp a c es `
Output: `Embedded-spaces`
Occurrences of more than `n' consecutive delimiters are removed
from the input string as it is copied to the output string.
IDL native code to perform the same operation (whitespace only):
Remove all instances of a whitespace.
output = strcompress( input, /REMOVE_ALL )
Remove all but one instance of a whitespace.
output = strcompress( input )
Note: strcompress accepts vector arguments.
1) If any of the input arguments, `delim', `n' or `input', is
undefined, an error is signaled by the IDL error handling
system.
2) If any of the input arguments, `delim', `n' or `input', is not
of the expected type, or it does not have the expected
dimensions and size, an error is signaled by the Icy
interface.
3) If the output argument `output' is not a named variable, an
error is signaled by the Icy interface.
None.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.1, 31-MAY-2021 (JDR)
Edited the header to comply with NAIF standard. Added example's
problem statement and reformatted example's output.
Added -Parameters, -Particulars, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
compress a character_string
|