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

28
LINES

< > BotCompany Repo | #1000636 // Compare strings with "==" instead of "equals" (JavaX translator)

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (1741L/11K/27K).

1  
// Syntax: s == "bla"
2  
3  
!636
4  
!JavaTok
5  
!sf
6  
7  
public class main {
8  
  public static void main(String[] args) throws Exception {
9  
    String s = loadMainJava();
10  
    
11  
    List<String> tok = JavaTok.split(s);
12  
    for (int i = 1; i+6 < tok.size(); i += 2)
13  
      if (Character.isLetter(tok.get(i).charAt(0))
14  
        && "!=".indexOf(tok.get(i+2)) >= 0 && tok.get(i+4).equals("=")
15  
        && tok.get(i+6).startsWith("\"")) {
16  
      String var = tok.get(i), str = tok.get(i+6);
17  
      boolean neg = tok.get(i+2).equals("!");
18  
      
19  
      for (int j = i; j <= i+6; j++)
20  
        tok.set(j, "");
21  
        
22  
      tok.set(i, (neg ? "!" : "") + str + ".equals(" + var + ")");
23  
      i += 6;
24  
    }
25  
26  
    saveMainJava(JavaTok.join(tok));
27  
  }
28  
}

Author comment

Began life as a copy of #1000635

Now handles != too

download  show line numbers  debug dex  old transpilations   

Travelled to 21 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, dhtvkmknsjym, gwrvuhgaqvyk, hxnwyiuffukg, ishqpsrjomds, jlatgrcjtklg, jtubtzbbkimh, liwcxgsjrgqn, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000636
Snippet name: Compare strings with "==" instead of "equals" (JavaX translator)
Eternal ID of this version: #1000636/1
Text MD5: ac8dbb1a94f9ad4e86830a7dc5e8f965
Transpilation MD5: 090df86ec6cbfa5d3747d39abf3f2e32
Author: stefan
Category:
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-04 21:50:17
Source code size: 742 bytes / 28 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 724 / 15452
Referenced in: [show references]