Wiki

Changes between Initial Version and Version 1 of Strings

Show
Ignore:
Timestamp:
11/13/09 13:00:38 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Strings

    v1 v1  
     1= Strings and characters =  
     2 
     3Strings are immutable sequential collections of char objects that represent a text string. 
     4 
     5In Cobra code these are typed as '''String'''  (on .Net this equates to System.String) 
     6{{{ 
     7var name as String 
     8def capitalize(title as String) 
     9}}} 
     10     
     11Within cobra you can catenate Strings explicitly with '+' 
     12{{{ 
     13s1 = 'my' + 'string'  # after which s1 == "mystring" 
     14}}} 
     15 
     16Cobra also supports Python-style string slicing: 
     17{{{ 
     18s = s[1:]  # chop off first char 
     19s = s[:-1] # chop off last char 
     20i = s.indexOf('foo') 
     21if i <> -1 
     22    s = s[:i]  # everything before 'foo' 
     23}}} 
     24Otherwise string manipulation is via the platform or Cobra runtime String and Char  
     25support methods. 
     26 
     27An index into a string gives the position of a char object which may be the start point of  
     28a substring. 
     29 
     30Chars are a representation of a single character (display glyph) in a string  
     31(for Unicode text a Unicode character) this is usually but may not necessarily be a single 
     32Char for a single glyph (see Unicode and multibyte or wide chars) 
     33 
     34 
     35== Literals == 
     36 
     37=== Char === 
     38 
     39Char literals are (usually) a single quoted character prefixed with a '''c'''. 
     40{{{ 
     41ch = c'x' 
     42}}} 
     43Can be single or double quote delimited (usually single). 
     44 
     45Cobra allows usual escape sequences for control characters 
     46     \n, \r, \t, \0 
     47{{{ 
     48nlch    = c'\n'   
     49tabch   = c'\t' 
     50nulCh   = c'\0'  
     51}}}   
     52 
     53=== String === 
     54Literal Strings are (single) single quote or double quote delimited  
     55('string' or "another string") 
     56 
     57All strings are single line (currently). 
     58 
     59A [] delimited expression in a string indicates interpolation or substitution of enclosed  
     60expression at that point. 
     61{{{ 
     62x='hops' 
     63print 'hi [x]'  # outputs: hi hops 
     64print "hi [x]"  # also outputs: hi hops 
     65 
     66print 'Hi [customer.firstName] [customer.lastName]' 
     67}}} 
     68leading [ can be escaped '\[' to escape this substitution. 
     69 
     70 
     71Literal strings support the usual escape characters. 
     72    \n - newline. 
     73    \r - carriage return. 
     74    \t - tab. 
     75    \0 - nul char. 
     76 
     77(arbitrary embedded hex or unicode ??) 
     78 
     79==== Raw Strings ==== 
     80    {{{r'string'}}} - unexpanded ('raw') string 
     81 
     82Does not interpret escape chars or substitute expressions in [] 
     83     
     84==== non Substituted strings ==== 
     85    {{{ns'string[x]'}}} or {{{ns"string[x]"}}} 
     86 
     87Does not do expression substitution - items in [] are treated as text 
     88 
     89Interprets escape chars but suppresses expression interpolation/substitution 
     90(handling of []) 
     91     
     92== !DocStrings == 
     93Single or multiline """ delimited text intended to document the item.  
     94 
     95Terminating trigraph must be on new line (after initiating line) or (single line docstring ) at end on same as start line. 
     96 
     97Allowed on File, (or after) class, struct, interface, var, def, sig, event, methods. 
     98    Usual form 
     99{{{ 
     100""" 
     101Heres the doc string 
     102""" 
     103}}} 
     104e.g. 
     105{{{ 
     106class BigOne 
     107    """ 
     108    Implementation of a BigOne thingy... 
     109    yadda yadda yadda 
     110    """ 
     111 
     112    var _initVal 
     113        "The initial BigOne value" 
     114}}} 
     115 
     116 
     117 
     118== Platform == 
     119 
     120There is another string form to allow inline c# src code to be inserted at 
     121the occurring position in generated source. 
     122 
     123    {{{sharp"c# src code"}}}  or {{{sharp'c# src code'}}}   
     124 
     125e.g. 
     126{{{ 
     127t = sharp'System.Type.GetType(qualifiedName)' 
     128}}} 
     129== Examples == 
     130{{{ 
     131s = 'A simple String' 
     132 
     133i=10 
     134ssub  = 'result is:[i]'    # ssub gets 'result is:10' 
     135 
     136ns0 = ns'result is:[i]'    # ns   gets 'result is:[i]'  
     137ns1 =   'result is:\[i]'   # ns1  gets 'result is:[i]'  
     138 
     139rs = r'here [is]\nsome\r'  # rs gets string 'here [is]\nsome\r' 
     140}}} 
     141== Notes == 
     142 
     143Idiomatically most textstrings in cobra use single-quote ' as delimiters unless need to 
     144enclose a '. 
     145 
     146Exact String and Char representation is platform dependent as are support and utility [[BR]] 
     147methods pending a complete portable Runtime library.[[BR]] 
     148In the meantime we are using platform (.Net and Mono) capabilities and semantics.  
     149 
     150Eventually there will be support for multiline text strings (embedded newlines from source representation). 
     151