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).

// Syntax: s == "bla"

!636
!JavaTok
!sf

public class main {
  public static void main(String[] args) throws Exception {
    String s = loadMainJava();
    
    List<String> tok = JavaTok.split(s);
    for (int i = 1; i+6 < tok.size(); i += 2)
      if (Character.isLetter(tok.get(i).charAt(0))
        && "!=".indexOf(tok.get(i+2)) >= 0 && tok.get(i+4).equals("=")
        && tok.get(i+6).startsWith("\"")) {
      String var = tok.get(i), str = tok.get(i+6);
      boolean neg = tok.get(i+2).equals("!");
      
      for (int j = i; j <= i+6; j++)
        tok.set(j, "");
        
      tok.set(i, (neg ? "!" : "") + str + ".equals(" + var + ")");
      i += 6;
    }

    saveMainJava(JavaTok.join(tok));
  }
}

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: 723 / 15451
Referenced in: #636 - Resolve symbolic translator invocations
#1000634 - Spike - find table names in MySQL dump
#1000642 - Find create statements in MySQL dump
#1000648 - Find field names in MySQL "create table"
#1000706 - Compare strings with "==" instead of "equals" (JavaX translator, transpiled)
#3000189 - Answer for stefanreich(>> t bla)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)