Module description

scf -- sscanf scanner
The scf module implements a simplified version of C's sscanf function. The words in this module expect a format string with specifiers &lb;see below for the format&rb;. For every specifier &lb;except %%&rb; the string is scanned and converted to a stack item. The white space character in the specifier string will match repeatedly all white space in the source string. All other characters must be matched in the source string.
                                                                      
Format: %[double]specifier                                                 
   Double: l      = the argument is interpreted as a double                
Specifier: c      = scan a character [char]                                
           d      = scan a signed number [n or d]                          
           o      = scan an unsigned octal [n or d]                        
           s      = scan a string [c-addr u]                               
           u      = scan an unsigned number [u or ud]                      
           x      = scan an unsigned hexadecimal number [u or ud]          
           X      = scan an unsigned hexadecimal number [u or ud]          
           e      = scan a float number [r]                                
           E      = scan a float number [r]                                
           q      = scan a quoted string &lb;non sprintf&rb; [c-addr u]    
           %      = match a '%' []                                         

sscanf words

scf+scan ( c-addr1 u1 c-addr2 u2 -- i*x j*r n )
Scan the source string c-addr1 u1 with specifier string c-addr2 u2, resulting in n arguments i*x j*r
scf" ( "ccc<quote>" c-addr u -- i*x j*r n )
Scan the source string c-addr1 u1 with the specifier string c-addr2 u2, resulting in n arguments i*x and j*r

Examples

\ ==============================================================================
\
\              scf_expl - the sscanf example in the ffl
\
\               Copyright (C) 2009  Dick van Oudheusden
\  
\ This library is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public
\ License as published by the Free Software Foundation; either
\ version 2 of the License, or (at your option) any later version.
\
\ This library is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
\ General Public License for more details.
\
\ You should have received a copy of the GNU General Public
\ License along with this library; if not, write to the Free
\ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\
\ ==============================================================================
\ 
\  $Date: 2008-09-22 18:46:53 $ $Revision: 1.2 $
\
\ ==============================================================================

include ffl/scf.fs

\ Conversions
.( Scan the string : ) 
s" 10 a hello CE 55 20" 2dup type     \ the source string
.(  with the specifiers: ) 
s" %d %c %s %x %o %ld"  2dup type cr  \ the specifier string

scf+scan                              \ scan the source string with the specifier string

.( Number of conversions: ) . cr      \ the number of conversions done by scf+scan
.( Double: ) d. cr                    \ the results
.( Octal: ) . cr
.( Hex: ) . cr
.( String: ) type cr
.( Character: ) emit cr
.( Decimal: ) . cr

\ Float conversions
[DEFINED] >float [IF]
.( Scan floats ) cr
s" 10 20.1 -30.3E+5" s" %e %e %e" scf+scan
.( Number of floats: ) . 
.(  values: ) f. f. f. cr
[THEN]

\ Matching and conversion
.( Match and scan, with parsing word ) cr
s" %var = 20 (24)" scf" %%%s = %d [%o]"

.( Number of conversions: ) .          \ Only 2 conversion due to mismatch of '['
.(  values: ) . type cr

Generated by fsdocgen 0.1.0