about summary refs log tree commit diff stats
path: root/src/ui/inputwin.c
Commit message (Collapse)AuthorAgeFilesLines
* Define POSIX macro to have strdupMichael Vetter2020-06-121-2/+2
| | | | | | | | | | | | | | https://github.com/profanity-im/profanity/commit/98c38dc6d6d29333c63f80327774f094610d8602 sets C99 as standard. strdup() is not part of C99. For now set `-D_POSIX_C_SOURCE=200809L` macro to have strdup() in C99. Using `gnu99` instead would be another option. We should take more care to use glib functions whenever possible. Regards https://github.com/profanity-im/profanity/issues/1357
* inp_readline() Correct slashguard featureMichael Vetter2020-04-211-4/+6
| | | | Protect against invalid reads by checking the length.
* Make _inp_edited() more robustDmitry Podgorny2020-04-191-1/+8
|
* Add slashguard featureMichael Vetter2020-03-181-0/+7
| | | | | New command `/slashguard` tries to protect against typing ` /quit` by not allowing a slash in the first 4 characters.
* Add vim modelineMichael Vetter2019-11-131-0/+1
|
* Fix add_history usage in down arrow handlerMichael Vetter2019-11-051-4/+1
| | | | | | | | | | | | | | [Programming with GNU History](http://www.math.utah.edu/docs/info/hist_2.html) mentions using_history(). Chet, maintainer of readline told me about it. (Thanks Chet!) Seems like we need to call this so that the history offset is at the right end of the list. I assume it's called in the linehandler automatically. Fix https://github.com/profanity-im/profanity/issues/200
* Store current input line in historyMichael Vetter2019-11-051-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Regards https://github.com/profanity-im/profanity/issues/200 This doesn't work yet. And I have no idea why. Weird behaviour: - start profanity - type 'ASDF' - ctrl+arrow down -> text vanishes (like intended) - arrow up -> nothing happens (intended is that the last history item [ASDF] appears) - type 'ABC' - press enter - arrow up -> ABC appears - enter - type 'UUU' - ctrl+arrow down - type 'ZZZ' - enter - arrow up - ZZZ appears - arrow up - UUU appears So in the latter case we added to history and deleted from the input line and then immediately entered new text and pressed enter, to add this to the history too. When we do this the not sent text succesfully was stored in history.
* Bind key to switch to next active windowMichael Vetter2019-09-301-0/+14
| | | | | | alt-a brings one to the next window with unread messages. Regards https://github.com/profanity-im/profanity/issues/1114
* Define keybindings to switch to up to 20 windowsMichael Vetter2019-09-301-0/+100
| | | | | | | | | | alt-2 brings one ot the window. irssi supports alt + 1234567890qwertyuio to easily switch to 20 windows instead of just ten. Hardcode this too. Regards https://github.com/profanity-im/profanity/issues/1114
* Update copyright to include 2019Michael Vetter2019-01-221-1/+1
|
* Add prof_win_close (#1017)twardziejszy2019-01-101-0/+11
|
* WIP add self prefs for statusbarJames Booth2018-03-101-2/+2
|
* Clear autocompletes on line editsJames Booth2018-02-091-3/+19
|
* Update copyrightJames Booth2018-01-211-1/+1
|
* Allow previous autocompletion with shift tabJames Booth2017-04-011-2/+49
|
* Update CopyrightJames Booth2017-01-281-1/+1
|
* Allow vertical positioning of all windowsJames Booth2016-09-231-10/+4
|
* Add /inputwin top|bottom commandJames Booth2016-09-191-1/+8
| | | | closes #853
* Move all filepath handling to files.cJames Booth2016-07-241-1/+1
|
* Move xgd functionsJames Booth2016-07-241-1/+2
|
* Tidy headersJames Booth2016-07-241-7/+7
|
* Moved roster_list.cJames Booth2016-07-241-1/+1
|
* Moved muc.cJames Booth2016-07-241-1/+1
|
* Moved chat_state.cJames Booth2016-07-241-1/+1
|
* Moved chat state handling code to chat_state.cJames Booth2016-07-241-2/+3
|
* Update GPL link in headersJames Booth2016-07-241-1/+1
|
* Rename command sourcesJames Booth2016-05-221-1/+1
|
* Add cmd_autocomplete.cJames Booth2016-05-201-3/+3
|
* Reorder headers in inputwin.cJames Booth2016-05-111-1/+1
| | | | Fixes unknown type name '_fpos64_t' error on Cygwin
* Implement XEP-0363: HTTP File UploadDominik Heidler2016-04-261-0/+3
|
* Removed #AX_PREFIX_CONFIG_HJames Booth2016-03-311-3/+3
|
* Merge branch 'master' into plugins-cJames Booth2016-02-141-1/+1
|\ | | | | | | | | | | Conflicts: src/main.c src/ui/console.c
| * Updated copyrightJames Booth2016-02-141-1/+1
| |
* | Added C plugin code from plugins branchJames Booth2016-02-141-3/+3
|/
* Added sys/select.h header includesJames Booth2016-01-191-0/+1
|
* Use MB_CUR_MAX when calculating cursor positionJames Booth2015-12-191-1/+1
|
* Read ~/.config/profanity/inputrcJames Booth2015-12-061-0/+7
|
* Renamed readline handlersJames Booth2015-12-061-93/+93
|
* Added readline function definitionsJames Booth2015-12-061-1/+24
|
* readline: set rl_outstream to /dev/nullJames Booth2015-12-011-0/+5
|
* Disable readline completionJames Booth2015-11-291-0/+3
|
* Clear Readline undo list when autocompleting command historyJames Booth2015-11-091-2/+2
| | | | fixes #667
* Renamed ui_switch_win -> ui_focus_winJames Booth2015-11-021-3/+3
|
* Removed ui_ paging functionsJames Booth2015-11-011-4/+8
|
* Removed inp_win_clear()James Booth2015-11-011-9/+0
|
* Removed ui_events moduleJames Booth2015-10-271-1/+0
|
* Removed ui_ev_focus_winJames Booth2015-10-271-3/+3
|
* Get rid of compiler warning concerning NULL pointerMichael Vetter2015-10-261-1/+1
| | | | Casting the into correct type.
* Applied coding style to src/ui/James Booth2015-10-251-2/+2
|
* Fixed resize during password and tls commandsJames Booth2015-10-061-0/+2
|
tle='author Kartik K. Agaram <vc@akkartik.com> 2015-06-23 14:02:12 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-06-23 14:02:12 -0700 1631 - update html versions' href='/akkartik/mu/commit/html/013literal_string.cc.html?h=hlt&id=dbe124108b7a3529feeeba91339928c4ac737072'>dbe12410 ^
76755b28 ^
dbe12410 ^
672e3e50 ^

9570363a ^
90560d71 ^
9570363a ^


76755b28 ^
9570363a ^
76755b28 ^

9570363a ^

672e3e50 ^
76755b28 ^

dbe12410 ^

90560d71 ^
dbe12410 ^
dbe12410 ^

90560d71 ^
76755b28 ^
4fe9f5e8 ^

dbe12410 ^
90560d71 ^

dbe12410 ^
76755b28 ^
dbe12410 ^

90560d71 ^


dbe12410 ^



76755b28 ^



672e3e50 ^



76755b28 ^
672e3e50 ^
4bbd3ded ^



76755b28 ^
dbe12410 ^





76755b28 ^
4bbd3ded ^
672e3e50 ^



76755b28 ^
672e3e50 ^
76755b28 ^


dbe12410 ^





76755b28 ^
dbe12410 ^







76755b28 ^
dbe12410 ^




76755b28 ^
672e3e50 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234



                                                                                          
                                        






                                                                                         

                                                                                                 
                        
                                  
                             

                              
                            
                               
                             






















                                                                                                                                                                           
                                                                                                          




                                                                                                               
                                                                                                              

                                                                                
                                                                                                                                                                                                                                         
 
                                                                                

                                                                                                                                                                                                                
                                                                                                                 

                                                                               


                                                                                                                                   
                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                          
                                                                                                                                     
      





                                                                                                                                         
                                                                                                                                                                                    
                                                                                                                                                    

                                                                                                                                                  
                                                                                                                 


                                                                                                                
                                                                                                                                               







                                                                                                               
                                                                                                                                                                                                    
                                                                                   
                                                                                                                                                    
                                                                                    

                                                                                                                                                  

                                                                              
                                                  


                                                                                                                                                                                           
                                  
                                                                                                                                                                                                                                             
                                                                                                                                                                                              
                                                                              
                                  


                                                                                                            
                                                                                                                                                                                                

                                                                                                                      

                                                                                                                                                  

                                                                              
                                                                                                                                              
                                                    
                                                                                                                                                                                                                                                                                                                                                                                                                            

                                                                              
                                                                                                                                              





                                                                                                                 
                                                                                                                                                                                    
                                  
                                                                                                                                                                                            
                                                                            

                                
                                                                             
                                                                                                                                                                                                                                                                           


                                                                                                                                                                                                        
                                                                              
                                          

                                                                                                                                                                                                                                                                                                                                                                   

                                                                        
 

                                                                                                       

                                                                               
                                                                                                                            
                                                                                                                                   

                                      
                                                                                                                                           
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

                                
                                                                                                                                      

                                                                                           
                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

                                


                                                                                                                                                                                                                                                                                   



                                                                                                                                                                                                                                     



                                                                                                                                                                                                                                                                                                                           



                                                                                                             
                                                                                                            
 



                                                                                                             
                                                                                                           





                                                                                                   
                                                                                                              
 



                                                                                                                                               
                                                            
                                                            


                                                                                                                                                                         





                                                                                   
                                                                                                           







                                                                                
                                                                                                                                          




                                                               
                                                                                                   



                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 014literal_string.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.traceContains { color: #008000; }
.cSpecial { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
.Constant { color: #00a0a0; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: For convenience, some instructions will take literal arrays of characters (strings).</span>
<span class="Comment">//:</span>
<span class="Comment">//: Instead of quotes, we'll use [] to delimit strings. That'll reduce the</span>
<span class="Comment">//: need for escaping since we can support nested brackets. And we can also</span>
<span class="Comment">//: imagine that 'recipe' might one day itself be defined in mu, doing its own</span>
<span class="Comment">//: parsing.</span>

<span class="Delimiter">:(scenarios load)</span>
<span class="Delimiter">:(scenario string_literal)</span>
recipe main [
  <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>copy [abc def]  <span class="Comment"># copy can't really take a string</span>
]
<span class="traceContains">+parse:   ingredient: {&quot;abc def&quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(scenario string_literal_with_colons)</span>
recipe main [
  <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>copy [abc:def/ghi]
]
<span class="traceContains">+parse:   ingredient: {&quot;abc:def/ghi&quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(before &quot;End Mu Types Initialization&quot;)</span>
put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;literal-string&quot;</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>

<span class="Delimiter">:(before &quot;End next_word Special-cases&quot;)</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  string result = slurp_quoted<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
  skip_whitespace_and_comments_but_not_newline<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
string slurp_quoted<span class="Delimiter">(</span>istream&amp; in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  ostringstream out<span class="Delimiter">;</span>
  assert<span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">));</span>  assert<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'['</span><span class="Delimiter">);</span>  out &lt;&lt; static_cast&lt;char&gt;<span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span>  <span class="Comment">// slurp the '['</span>
  if <span class="Delimiter">(</span>is_code_string<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">))</span>
    slurp_quoted_comment_aware<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">);</span>
  else
    slurp_quoted_comment_oblivious<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">);</span>
  <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span>
<span class="Delimiter">}</span>

<span class="Comment">// A string is a code string if it contains a newline before any non-whitespace</span>
<span class="Comment">// todo: support comments before the newline. But that gets messy.</span>
bool is_code_string<span class="Delimiter">(</span>istream&amp; in<span class="Delimiter">,</span> ostream&amp; out<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  while <span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    char c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
    if <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>c<span class="Delimiter">))</span> <span class="Delimiter">{</span>
      in<span class="Delimiter">.</span>putback<span class="Delimiter">(</span>c<span class="Delimiter">);</span>
      <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    out &lt;&lt; c<span class="Delimiter">;</span>
    if <span class="Delimiter">(</span>c == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Comment">// Read a regular string. Regular strings can only contain other regular</span>
<span class="Comment">// strings.</span>
void slurp_quoted_comment_oblivious<span class="Delimiter">(</span>istream&amp; in<span class="Delimiter">,</span> ostream&amp; out<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  int brace_depth = <span class="Constant">1</span><span class="Delimiter">;</span>
  while <span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    char c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
    if <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      out &lt;&lt; static_cast&lt;char&gt;<span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span>
      <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    out &lt;&lt; c<span class="Delimiter">;</span>
    if <span class="Delimiter">(</span>c == <span class="Constant">'['</span><span class="Delimiter">)</span> ++brace_depth<span class="Delimiter">;</span>
    if <span class="Delimiter">(</span>c == <span class="Constant">']'</span><span class="Delimiter">)</span> --brace_depth<span class="Delimiter">;</span>
    if <span class="Delimiter">(</span>brace_depth == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  if <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">)</span> &amp;&amp; brace_depth &gt; <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise_error &lt;&lt; <span class="Constant">&quot;unbalanced '['</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    out<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Comment">// Read a code string. Code strings can contain either code or regular strings.</span>
void slurp_quoted_comment_aware<span class="Delimiter">(</span>istream&amp; in<span class="Delimiter">,</span> ostream&amp; out<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  char c<span class="Delimiter">;</span>
  while <span class="Delimiter">(</span>in &gt;&gt; c<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    if <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      out &lt;&lt; static_cast&lt;char&gt;<span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span>
      <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    if <span class="Delimiter">(</span>c == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      out &lt;&lt; c<span class="Delimiter">;</span>
      while <span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>in<span class="Delimiter">)</span> &amp;&amp; in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out &lt;&lt; static_cast&lt;char&gt;<span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">());</span>
      <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    if <span class="Delimiter">(</span>c == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      in<span class="Delimiter">.</span>putback<span class="Delimiter">(</span>c<span class="Delimiter">);</span>
      <span class="Comment">// recurse</span>
      out &lt;&lt; slurp_quoted<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
      <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    out &lt;&lt; c<span class="Delimiter">;</span>
    if <span class="Delimiter">(</span>c == <span class="Constant">']'</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  raise_error &lt;&lt; <span class="Constant">&quot;unbalanced '['</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  out<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(after &quot;Parsing reagent(string s)&quot;)</span>
if <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'['</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  assert<span class="Delimiter">(</span>*s<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">']'</span><span class="Delimiter">);</span>
  <span class="Comment">// delete [] delimiters</span>
  s<span class="Delimiter">.</span>erase<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span>
  strip_last<span class="Delimiter">(</span>s<span class="Delimiter">);</span>
  name = s<span class="Delimiter">;</span>
  type = new type_tree<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
  properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair&lt;string<span class="Delimiter">,</span> string_tree*&gt;<span class="Delimiter">(</span>name<span class="Delimiter">,</span> new string_tree<span class="Delimiter">(</span><span class="Constant">&quot;literal-string&quot;</span><span class="Delimiter">)));</span>
  <span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Comment">//: Unlike other reagents, escape newlines in literal strings to make them</span>
<span class="Comment">//: more friendly to trace().</span>

<span class="Delimiter">:(after &quot;string reagent::to_string()&quot;)</span>
  if <span class="Delimiter">(</span>is_literal_string<span class="Delimiter">(</span>*this<span class="Delimiter">))</span>
    <span class="Identifier">return</span> emit_literal_string<span class="Delimiter">(</span>name<span class="Delimiter">);</span>

<span class="Delimiter">:(code)</span>
bool is_literal_string<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second &amp;&amp; x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">-&gt;</span>value == <span class="Constant">&quot;literal-string&quot;</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

string emit_literal_string<span class="Delimiter">(</span>string name<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  size_t pos = <span class="Constant">0</span><span class="Delimiter">;</span>
  while <span class="Delimiter">(</span>pos != string::npos<span class="Delimiter">)</span>
    pos = replace<span class="Delimiter">(</span>name<span class="Delimiter">,</span> <span class="Constant">&quot;</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;</span><span class="cSpecial">\\</span><span class="Constant">n&quot;</span><span class="Delimiter">,</span> pos<span class="Delimiter">);</span>
  <span class="Identifier">return</span> <span class="Constant">&quot;{</span><span class="cSpecial">\&quot;</span><span class="Constant">&quot;</span>+name+<span class="Constant">&quot;</span><span class="cSpecial">\&quot;</span><span class="Constant">: </span><span class="cSpecial">\&quot;</span><span class="Constant">literal-string</span><span class="cSpecial">\&quot;</span><span class="Constant">}&quot;</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

size_t replace<span class="Delimiter">(</span>string&amp; str<span class="Delimiter">,</span> const string&amp; from<span class="Delimiter">,</span> const string&amp; to<span class="Delimiter">,</span> size_t n<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  size_t result = str<span class="Delimiter">.</span>find<span class="Delimiter">(</span>from<span class="Delimiter">,</span> n<span class="Delimiter">);</span>
  if <span class="Delimiter">(</span>result != string::npos<span class="Delimiter">)</span>
    str<span class="Delimiter">.</span>replace<span class="Delimiter">(</span>result<span class="Delimiter">,</span> from<span class="Delimiter">.</span>length<span class="Delimiter">(),</span> to<span class="Delimiter">);</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

void strip_last<span class="Delimiter">(</span>string&amp; s<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  if <span class="Delimiter">(</span>!s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> s<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>s<span class="Delimiter">)</span>-<span class="Constant">1</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario string_literal_nested)</span>
recipe main [
  <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>copy [abc [def]]
]
<span class="traceContains">+parse:   ingredient: {&quot;abc [def]&quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(scenario string_literal_escaped)</span>
recipe main [
  <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>copy [abc \[def]
]
<span class="traceContains">+parse:   ingredient: {&quot;abc [def&quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(scenario string_literal_escaped_comment_aware)</span>
recipe main [
  <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>copy [
abc \\\[def]
]
<span class="traceContains">+parse:   ingredient: {&quot;\nabc \[def&quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(scenario string_literal_and_comment)</span>
recipe main [
  <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span>copy [abc]  <span class="Comment"># comment</span>
]
<span class="traceContains">+parse: --- defining main</span>
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse:   number of ingredients: 1</span>
<span class="traceContains">+parse:   ingredient: {&quot;abc&quot;: &quot;literal-string&quot;}</span>
<span class="traceContains">+parse:   product: {&quot;1&quot;: &lt;&quot;address&quot; : &lt;&quot;array&quot; : &lt;&quot;character&quot; : &lt;&gt;&gt;&gt;&gt;}</span>

<span class="Delimiter">:(scenario string_literal_escapes_newlines_in_trace)</span>
recipe main [
  copy [abc
def]
]
<span class="traceContains">+parse:   ingredient: {&quot;abc\ndef&quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(scenario string_literal_can_skip_past_comments)</span>
recipe main [
  copy [
    <span class="Comment"># ']' inside comment</span>
    bar
  ]
]
<span class="traceContains">+parse:   ingredient: {&quot;\n    # ']' inside comment\n    bar\n  &quot;: &quot;literal-string&quot;}</span>

<span class="Delimiter">:(scenario string_literal_empty)</span>
recipe main [
  copy []
]
<span class="traceContains">+parse:   ingredient: {&quot;&quot;: &quot;literal-string&quot;}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->