Returns a valid ObjC string literal (excluding quotes).
6956
public static String escapeStringLiteral(String s) {
    StringBuilder sb = null;
    int len = s.length();
    int lastIndex = 0;
    for (int i = 0; i < len; i++) {
      String replacement = escapeCharacterForStringLiteral(s.charAt(i), s, i);
      if (replacement == null) {
        continue;
      }
      if (sb == null) {
        sb = new StringBuilder();
      }
      if (lastIndex < i) {
        sb.append(s.substring(lastIndex, i));
      }
      lastIndex = i + 1;
      sb.append(replacement);
    }
    if (sb != null) {
      sb.append(s.substring(lastIndex, len));
      return sb.toString();
    } else {
      return s;
    }
  }
837593
def check_str(obj):
        
        if isinstance(obj, str):
            return obj
        if isinstance(obj, float):
            return str(int(obj))
        else:
            return str(obj)
1026890
def unquoted(cls, value, literal=False):
        """"""
        return cls(value, quotes=None, literal=literal)
1311631
def qual(obj):
    
    return u'{}.{}'.format(obj.__class__.__module__, obj.__class__.__name__)
1254885
function() {
        var str = "",
          quote = exprI(index++),
          closed = false,
          ch;

        while (index < length) {
          ch = exprI(index++);
          if (ch === quote) {
            closed = true;
            break;
          } else if (ch === "\\") {
            // Check for all of the common escape codes
            ch = exprI(index++);
            switch (ch) {
              case "n":
                str += "\n";
                break;
              case "r":
                str += "\r";
                break;
              case "t":
                str += "\t";
                break;
              case "b":
                str += "\b";
                break;
              case "f":
                str += "\f";
                break;
              case "v":
                str += "\x0B";
                break;
              default:
                str += "\\" + ch;
            }
          } else {
            str += ch;
          }
        }

        if (!closed) {
          throwError('Unclosed quote after "' + str + '"', index);
        }

        return {
          type: code.LITERAL,
          value: str,
          raw: quote + str + quote
        };
      }
750824
def to_string(self, obj):
        
        stream = NativeIO()
        self.to_stream(obj, stream)
        return text_(stream.getvalue(), encoding=self.encoding)
1193435
def quoting_nsarg(nsarg_value):
    
    quoted = re.findall(r'^"(.*)"$', nsarg_value)

    if re.search(
        r"[),\s]", nsarg_value
    ):  # quote only if it contains whitespace, comma or ')'
        if quoted:
            return nsarg_value
        else:
            return f'"{nsarg_value}"'
    else:
        if quoted:
            return quoted[0]
        else:
            return nsarg_value
52250
def _encode_str(self, obj, escape_quotes=True):
        """"""
        def replace(match):
            s = match.group(0)
            try:
                if escape_quotes:
                    return ESCAPE_DCT[s]
                else:
                    return BASE_ESCAPE_DCT[s]
            except KeyError:
                n = ord(s)
                if n < 0x10000:
                    return '\\u{0:04x}'.format(n)
                else:
                    # surrogate pair
                    n -= 0x10000
                    s1 = 0xd800 | ((n >> 10) & 0x3ff)
                    s2 = 0xdc00 | (n & 0x3ff)
                    return '\\u{0:04x}\\u{1:04x}'.format(s1, s2)
        if escape_quotes:
            return '"' + ESCAPE_ASCII.sub(replace, obj) + '"'
        else:
            return BASE_ESCAPE_ASCII.sub(replace, obj)
264943
static String quoteIfNeeded(String source) {
        String trimmed = source.trim();

        if (isObject(trimmed) || isArray(trimmed) || isString(trimmed)
            || isBoolean(trimmed) || isNull(trimmed)
            || isNumber(trimmed)) {
            return source;
        } else {
            return "\"" + source + "\"";
        }
    }
1037830
def safe_str(obj):
    
    try:
        return str(obj)
    except UnicodeEncodeError:
        # obj is unicode
        try:
            return unicode(obj).encode('unicode_escape')  # noqa for undefined-variable
        except NameError:
            # This is Python 3, just return the obj as it's already unicode
            return obj
757534
def one_liner_str(self):
        """"""
        assert self.less_attrs is not None, "Forgot to set attrs class variable"
        s_format = "{}={}"
        s = "; ".join([s_format.format(x, self.__getattribute__(x)) for x in self.less_attrs])
        return s
702614
public static boolean isString( Object obj ) {
      if( (obj instanceof String)
            || (obj instanceof Character)
            || (obj != null && (obj.getClass() == Character.TYPE || String.class.isAssignableFrom( obj.getClass() ))) ){
         return true;
      }
      return false;
   }
1005986
def string_literal(self):
        
        return quotedString.setParseAction(
            lambda s, l, t: "'{string}'".format(string=removeQuotes(s, l, t)))
943422
def _check_str_value(x):
    """"""
    if isinstance(x, str):
        # remove commas, and single quotation marks since loadarff cannot deal with it
        x = x.replace(",", ".").replace(chr(0x2018), "'").replace(chr(0x2019), "'")

        # put string in double quotes
        if " " in x:
            if x[0] in ('"', "'"):
                x = x[1:]
            if x[-1] in ('"', "'"):
                x = x[:len(x) - 1]
            x = '"' + x.replace('"', "\\\"") + '"'
    return str(x)
1339231
def value_to_string(self, obj):
        
        value = self.value_from_object(obj)
        return self.get_prep_value(value)
1182918
function ( obj, arg ) {
		arg = arg || ",";

		return string.trim( obj ).split( new RegExp( "\\s*" + arg + "\\s*" ) );
	}
538197
def is_string(obj):
    
    if PYTHON3:
        str_type = (bytes, str)
    else:
        str_type = (bytes, str, unicode)
    return isinstance(obj, str_type)