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

13
LINES

< > BotCompany Repo | #1032383 // safeBashQuote function - single quotes

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

Libraryless. Click here for Pure Java version (38L/1K).

/** possibly improvable */
sS safeBashQuote(String text) {
  if (text == null) return null;
  return "'" + text
    .replace("\\", "\\\\")
    .replace("'", "\\'")
    .replace("\n", "\\n")
    .replace("\r", "\\r") + "'";
}

sS safeBashQuote(File f) {
  ret safeBashQuote(f.getAbsolutePath());
}

Author comment

Began life as a copy of #1000832

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032383
Snippet name: safeBashQuote function - single quotes
Eternal ID of this version: #1032383/1
Text MD5: 66479fb8e7aacbf642e2afdbb270e571
Transpilation MD5: c08ea45e66595ccd5ef3e897a1abab8a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-02 02:58:31
Source code size: 308 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 66 / 101
Referenced in: [show references]