home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / comms_networking / zonk / rawdocs / fstrin < prev    next >
Encoding:
Text File  |  1999-02-13  |  6.8 KB  |  106 lines

  1. $zonkpage 1.07
  2.  
  3. $usetemplate: tpl.cmd/tpl
  4.  
  5. title: Appendix B - Format strings
  6.  
  7. text:{
  8.  
  9. A format string is a string which may contain <var>format specifiers</var> and <var>escape sequences</var>. Any character which is not part of one of these is treated as a literal character and is copied directly to the output string.
  10.  
  11. If the value to be formatted is being treated as a date see the <a href="#dates">seperate section below</a> otherwise for format strings which are used with values treated as strings, integers or floating point the <var>format specifiers</var> and <var>escape sequences</var> are those provided in standard ANSI c. The general form of a <var>format specifier</var> is
  12.  
  13. <lit>%<var>width></var>[.<var>precision</var>]<var>type</var></lit> 
  14.  
  15. where <var>type</var> is one of the following characters:
  16.  
  17. <ul>
  18. d, i - decimal integer
  19. o - unsigned octal
  20. x, X - unsigned hexadecimal
  21. u * not applicable to Zonk *
  22. c * not applicable to Zonk *
  23. s - character string
  24. f - floating-point number
  25. e, E - floating-point number in exponential format
  26. g, G - floating-point number in either fixed decimal or exponential format, whichever is more compact
  27. </ul>
  28.  
  29. Remember: you must use the appropriate Zonk 'treatas' (# for integer, ~ for floating point) modifier on the variable name corresponding to the format specifier you use, otherwise you will get junk output. For octal and hexadecimal output the modifier should be #. No modifier is required for string output.
  30.  
  31. Also remember that in <ref ctagv>zonk tagvalue</r> you should only have one <var>format specifier</var> in your format but with <ref cmakt>zonk maketag</r> you should have as many as the number of variables you name.
  32.  
  33. To output a percent sign use <lit>%%</lit> 
  34.  
  35. <var>width</var> is a number that represents the minimum field for displaying a number. The number is right justified unless z negative is used, in which case the number is left justified. If the value to be output would not fit in the width specified then the width is automatically expanded to the minimum needed, the number is never truncated. Thus is no field width is given, the minimun needed will be used.
  36.  
  37. The <var>precision</var> after the decimal point will force an integer value to have at least that many digits, using leading zeros if necessary. For a floating-point value it represents the number of decimal places to use.
  38.  
  39. <var>escape sequences</var> take the general form <lit>\<var>character</var></lit> where <var>character</var> may be
  40.  
  41. <ul>
  42. n - new line
  43. r - carriage return
  44. \ - backslash
  45. </ul>
  46.  
  47. <a name="dates"></a><sh>Date formats</sh>
  48.  
  49. When you request that a variable be treated as a date (using the @ modifier) then you should use a date format string. Again the string may contain <var>format specifiers</var> and <var>escape sequences</var> (as above). Any character which is not part of one of these is treated as a literal character and is copied directly to the output string.
  50.  
  51. The general form of a date <var>format specifier</var> is
  52.  
  53. <lit>&[z]<var>twolettercode</var></lit> where <var>twolettercode</var> can be any of
  54.  
  55. <ul>
  56. SE - Seconds
  57. MI - Minutes
  58. 12 - Hours in 12-hour format
  59. 24 - Hours in 24-hour format
  60. AM - AM or PM indicator
  61. WE - Weekday name in full
  62. W3 - 3-Character weekday abbreviation
  63. WN - Weekday number (Sunday=0 to Saturday=6)
  64. DY - Day of the month
  65. ST - Ordinal suffix (eg st,nd etc) apropriate for day number
  66. MO - Month name in full
  67. M3 - 3-Character abbreviation of month name
  68. MN - Month number
  69. MR - Month number in Roman numerals
  70. CE - Century
  71. YR - Year within century
  72. WK - Week of year
  73. DN - Day of the year
  74. TZ - Timezone (if known otherwise the empty string)
  75. </ul>
  76.  
  77. Numerical items are by default output with leading zeros, prefix the code with 'z' to suppress them. 'z' has no effect no textual items but is not faulted.
  78.  
  79. Date <var>format specifiers</var> are not case sensitive, however there is an additional feature for textual items whereby if the first letter of the <var>twolettercode</var> is in upper case then the textual string will be returned in upper case, otherwise it will be returned in lower case (with initial capital if appropriate).
  80.  
  81. To insert an '&' use '&&'. An invalid date format specifier is passed to the output string as is.
  82.  
  83. Some of you my realise that these specifiers are nearly identical to the ones RISC-OS provides. However Zonk does not use the RISC-OS system routines for dates in order that the code is easily portable to Windows and MacOS. One side effect of this is that, at the current time, there is no local language support. All text output is in English.
  84.  
  85. Before Zonk can output a date format it needs to parse the string value of the variable to try to interpret it as a date. Zonk has a very liberal date parser whereby, if the string can possibly be a date or part of a date, Zonk will treat it as such. Any missing parts are filled in from the current date. Zonk does not always get it right with partial dates especially if they are all numbers but it usually does. Two or three colon-seperated number parts (e.g. 12:34:12) are always treated as a time.
  86.  
  87. When Zonk encounters a two-digit year it will assume a century of '19' for anything in the range 80-99 and a century of '20' for anything else. Remember though, two digit years are bad...
  88.  
  89. By default Zonk interprets numeric dates in UK format that is day-month-year however if the date does not make sense that way round (eg 4/24/1999) then Zonk will try the US format month-day-year. However if you would prefer to use US date format there is a switch in the <ref sconf>configuration file</r> which reverses the default behaviour.
  90.  
  91. If Zonk is unable to understand the date for some reason then the output format will be ignored and you will get an error message instead.
  92.  
  93. As with date output, there is presently no local language support. Only English is understood for textual parts of the input date.
  94.  
  95. Remember, if you want the current date and/or time you can use %now, without a format for a default date/time string or as %now@ with a format to output it the way you want.
  96.  
  97. <sh>Translating between time zones.</sh>
  98.  
  99. If the input string has a recognisable timezone part (eg. GMT, EST, etc or a numeric offset such as -0800) then you can ask Zonk to convert the time/date to either GMT or your computer's local time. To do this, start the date format string with either <lit>#gmt:</lit> or <lit>#local:</lit> Note that these directives <i>are</i> case sensitive, they must be in lower case and that there must be <i>no whitespace</i> before them e.g.
  100.  
  101. <lit><zonk tagvalue mydate@ format (#gmt:&24:&mi:&se &tz)></lit> 
  102.  
  103. (in this example &tz will print as GMT and not the original time zone, similarly, if you use <lit>#local:</lit> then &tz will give the zonename that your computer is currently set to)
  104.  
  105. If there is no timezone part in the input string then no time offset is applied since Zonk has no way of knowing what the zone of the original time is and &tz will return an empty string.
  106.