1 | Index: Source/BackEndClr/SharpGenerator.cobra |
---|
2 | =================================================================== |
---|
3 | --- Source/BackEndClr/SharpGenerator.cobra (revision 2174) |
---|
4 | +++ Source/BackEndClr/SharpGenerator.cobra (working copy) |
---|
5 | @@ -3749,8 +3749,33 @@ |
---|
6 | |
---|
7 | get asSharp as String is override |
---|
8 | return Utils.sharpStringLiteralFor(_string) |
---|
9 | + |
---|
10 | + def writeSharpDef(sw as CurlyWriter, parens as bool) is override |
---|
11 | + if _string.contains(sharp'"\u2028"') # unicode line seperator |
---|
12 | + _expandPlatformNewline(sw) |
---|
13 | + return |
---|
14 | |
---|
15 | - |
---|
16 | + s = .asSharp |
---|
17 | + sw.write(s) |
---|
18 | + |
---|
19 | + def _expandPlatformNewline(sw as CurlyWriter) |
---|
20 | + ucodeLineSep as char = sharp"'\u2028'" |
---|
21 | + l = List<of String>(_string.split( @[ucodeLineSep] )) |
---|
22 | + if l.count == 1 # false alarm no \N |
---|
23 | + sw.write(.asSharp) |
---|
24 | + return |
---|
25 | + |
---|
26 | + sep = '' |
---|
27 | + sw.write('CobraLangInternal.CobraImp.MakeString(') |
---|
28 | + for s0 in l[:-1] |
---|
29 | + sw.write(sep) |
---|
30 | + sw.write(Utils.sharpStringLiteralFor(s0)) |
---|
31 | + sw.write(',CobraLangInternal.CobraImp._printStringMaker.MakeString(Cobra.Lang.CobraCore.NewLine)') |
---|
32 | + sep = ',' |
---|
33 | + sw.write(sep) |
---|
34 | + sw.write(Utils.sharpStringLiteralFor(l.last)) |
---|
35 | + sw.write(')') |
---|
36 | + |
---|
37 | class StringSubstLit |
---|
38 | is partial |
---|
39 | |
---|
40 | Index: Source/CobraTokenizer.cobra |
---|
41 | =================================================================== |
---|
42 | --- Source/CobraTokenizer.cobra (revision 2174) |
---|
43 | +++ Source/CobraTokenizer.cobra (working copy) |
---|
44 | @@ -705,6 +705,9 @@ |
---|
45 | # cannot have `last` being a backslash anymore--it's considered consumed now |
---|
46 | last = c'\0' |
---|
47 | continue |
---|
48 | + on c'N' # platfrom indep line termin |
---|
49 | + #chars.append(Environment.newLine) |
---|
50 | + chars.append(sharp"'\u2028'") # unicode line separator |
---|
51 | else, next = c # TODO: should probably be error: Invalid escape sequence |
---|
52 | else if c<>'\\' |
---|
53 | next = c |
---|
54 | Index: Tests/100-basics/068-string-termin.cobra |
---|
55 | =================================================================== |
---|
56 | --- Tests/100-basics/068-string-termin.cobra (revision 0) |
---|
57 | +++ Tests/100-basics/068-string-termin.cobra (revision 0) |
---|
58 | @@ -0,0 +1,10 @@ |
---|
59 | +# Test for platform independent line terminator metacharacter in strings |
---|
60 | +class Test |
---|
61 | + def main is shared |
---|
62 | + assert "\N" == Environment.newLine |
---|
63 | + assert '\N' == Environment.newLine |
---|
64 | + s = "\\N" |
---|
65 | + assert not s == Environment.newLine |
---|
66 | + assert s.length == 2 |
---|
67 | + assert s == r'\N' |
---|
68 | + assert not r'\N' == Environment.newLine |
---|
69 | Index: Developer/IntermediateReleaseNotes.text |
---|
70 | =================================================================== |
---|
71 | --- Developer/IntermediateReleaseNotes.text (revision 2174) |
---|
72 | +++ Developer/IntermediateReleaseNotes.text (working copy) |
---|
73 | @@ -48,6 +48,8 @@ |
---|
74 | |
---|
75 | * Sets with duplicate members such as `{1, 0, 1}` now generate a warning. |
---|
76 | |
---|
77 | +* Add support for \N metacharacter in strings for platform-sensitive line terminator. ticket:42 |
---|
78 | + |
---|
79 | ================================================================================ |
---|
80 | Library |
---|
81 | ================================================================================ |
---|