Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > BotCompany Repo | #1025352 // magicQuotes

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2502L/16K).

1  
// effort doubles for each extra token
2  
static int magicQuotes_maxTokens = 10;
3  
4  
static Set<S> magicQuotes(S input) {
5  
  new LinkedHashSet<S> out;
6  
  LS tok = javaTok(input);
7  
  if (l(tok) <= magicQuotes_maxTokens)
8  
    magicQuotes_impl(new L, asLinkedList(tok), false, out);
9  
  ret out;
10  
}
11  
12  
// Q: do remainingTokens start with an N or C token?
13  
svoid magicQuotes_impl(LS tokens, LS remainingTokens, bool inQuote, Set<S> out) {
14  
  ping();
15  
  if (l(remainingTokens) < 2)
16  
    out.add(inQuote ? join(tokens) + "\"" + join(remainingTokens) : join(tokens) + join(remainingTokens));
17  
  else {
18  
    // case 1: don't insert a quote
19  
    
20  
    tokens.addAll(popFirst(2, remainingTokens));
21  
    magicQuotes_impl(tokens, remainingTokens, inQuote, out);
22  
    remainingTokens.addAll(0, popLast(2, tokens));
23  
    
24  
    // case 2: insert quote
25  
    
26  
    LS t = cloneTakeFirst(2, remainingTokens);
27  
    if (inQuote)
28  
      addAll(tokens, "\"" + first(t), second(t));
29  
    else
30  
      addAll(tokens, first(t), "\"" + second(t));
31  
    removeFirst(2, remainingTokens);
32  
    magicQuotes_impl(tokens, remainingTokens, !inQuote, out);
33  
    removeLast(2, tokens);
34  
    remainingTokens.addAll(0, t);
35  
  }
36  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025352
Snippet name: magicQuotes
Eternal ID of this version: #1025352/13
Text MD5: 1c7a3c2b2a2394da15913b5389abf055
Transpilation MD5: 3409a4d055536af8d0daa2c4de262132
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-01 21:31:03
Source code size: 1188 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 160 / 274
Version history: 12 change(s)
Referenced in: [show references]