PreviousUpNext

15.3.440  src/lib/src/sfprintf.api

## sfprintf.api

# Compiled by:
#     src/lib/std/standard.lib



# Formatted conversion to and from strings.

stipulate
    package f8b =  eight_byte_float;                                    # eight_byte_float              is from   src/lib/std/eight-byte-float.pkg
    package fil =  file__premicrothread;                                # file__premicrothread          is from   src/lib/std/src/posix/file--premicrothread.pkg
    package pf  =  printf_field;                                        # printf_field                  is from   src/lib/src/printf-field.pkg
    package qs  =  quickstring__premicrothread;                         # quickstring__premicrothread   is from   src/lib/src/quickstring--premicrothread.pkg
herein


    # This api is implemented in:
    #
    #     src/lib/src/sfprintf.pkg
    #
    api Sfprintf {

        Printf_Arg
          = QUICKSTRING   qs::Quickstring
          | LINT   large_int::Int
          | INT    int::Int
          | LUNT   large_unt::Unt
          | UNT    unt::Unt
          | UNT8   one_byte_unt::Unt
          | BOOL   Bool
          | CHAR   Char
          | STRING String
          | FLOAT  f8b::Float
          | LEFT  ((Int, Printf_Arg))           #  Left  justify in field of given width.
          | RIGHT ((Int, Printf_Arg))           #  Right justify in field of given width.
          ;

        exception BAD_FORMAT String;            #  Bad format string 
        exception BAD_FORMAT_LIST;              #  raised on specifier/item type mismatch 

        sprintf':                          String -> List( Printf_Arg ) -> String;
        fnprintf': (String -> Void)     -> String -> List( Printf_Arg ) -> Void;
        fprintf':    fil::Output_Stream -> String -> List( Printf_Arg ) -> Void;
        printf':                           String -> List( Printf_Arg ) -> Void;



        # Obscure stuff

        # The following few can be used to mechanically
        # synthesize an appropriate arglist from a
        # sfprintf format string like "%d %6.2f\n"

        parse_format_string_into_printf_field_list              # Digest a printf-style format string  like "This is %d %2.3f"
            :                                                   # into a list of Printf_Field records -- see src/lib/src/printf-field.pkg
            String -> List( pf::Printf_Field );

        printf_field_type_to_printf_arg_list
            :
            pf::Printf_Field_Type
            ->
            List( Printf_Arg );

    };
end;

## AUTHOR:   John Reppy
##          AT&T Bell Laboratories
##          Murray Hill, NJ 07974
##          jhr@research.att.com
## COPYRIGHT (c) 1992 by AT&T Bell Laboratories.  See SMLNJ-COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext