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

35
LINES

< > BotCompany Repo | #1002056 // C# to JavaX Translator (googleMe function) - WORKS

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1540L/11K/34K).

!752

p {
  L<S> tok = javaTok(loadSnippet("#1002054")); // googleMe
  
  // classes are UPPER case!
  
  replaceToken(tok, "string", "String");
  
  // ...while methods are LOWER case.
  
  replaceToken(tok, "Split", "split");
  replaceToken(tok, "Equals", "equals");
  replaceToken(tok, "Add", "add");
  replaceToken(tok, "ToLower", "toLowerCase");

  // some syntax
  replaceToken(tok, "in", ":");
  replaceToken(tok, "foreach", "for");
  
  // split function takes a string in Java
  for (int i = 1; i+6 < l(tok); i += 2)
    if (eq(tok.get(i), "split") && eq(tok.get(i+2), "(") && tok.get(i+4).startsWith("'") && eq(tok.get(i+6), ")"))
      tok.set(i+4, charToStringLiteral(tok.get(i+4)));

  jreplace(tok, "new List", "new ArrayList");
  jreplace(tok, ".Count", ".size()");
  jreplace(tok, "[*]", ".get($2)");
  jreplace(tok, "Uri.EscapeDataString", "urlencode");
  print(join(tok));
}

static S charToStringLiteral(S s) {
  ret "\"" + s.charAt(1) + "\""; // todo: special cases
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002056
Snippet name: C# to JavaX Translator (googleMe function) - WORKS
Eternal ID of this version: #1002056/1
Text MD5: 04804ac9a12ffc8dccaaf6e857b61eb0
Transpilation MD5: d125be56b90419e5c0f8179024c80515
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-23 00:22:14
Source code size: 1021 bytes / 35 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 621 / 616
Referenced in: [show references]