working on it ...

Filters

Explore Public Snippets

Sort by

Found 3 snippets matching: unicodestring

    public by MarcoDeMagistris  559026  64  7  0

    Converts Unicode string to Ansi String

    Converts Unicode string to Ansi String
    public static string ConvertUnicodeToAnsi(String s)
            {
                /// <summary>
                /// Description: Converts Unicode string to Ansi String
                ///              
                /// </summary>
                /// <exception cref="ArgumentNullException"></code></exception>
                /// <exception cref="EncoderExceptionFallback"></exception>
                /// <exception cref="DecoderExceptionFallback"></exception>
                /// <exception cref="ArgumentException"></exception>
                try
                {
                    byte[] unicodeBytes = Encoding.Unicode.GetBytes(s);
                    byte[] ansiBytes = Encoding.Convert(Encoding.Unicode, Encoding.Default, unicodeBytes);
                    return Encoding.Default.GetString(ansiBytes).ToString();
                }
                catch {
                    throw;
                }
            }

    external by Johan Hernandez  46  0  1  0

    Convert NSString to icu::UnicodeString back and forth

    Convert NSString to icu::UnicodeString back and forth: NSString+UnicodeString.mm
    //
    //  NSString+UnicodeString.m
    //
    //  Created by Johan Hernandez on 1/18/15.
    //  Copyright (c) 2015 Bithavoc.io - All rights reserved.
    //
    
    #import "NSString+UnicodeString.hh"
    #include <string>
    
    @implementation NSString (UnicodeString)
    
    + (NSString*)stringWithUnicodeString:(const icu::UnicodeString&) ustr {
        std::string str;
        ustr.toUTF8String(str);
        return [NSString stringWithUTF8String:str.c_str()];
    }
    
    + (NSString*)stringWithStdString:(const std::string&) str {
        return [NSString stringWithUTF8String:str.c_str()];
    }
    
    - (icu::UnicodeString) UnicodeString {
        return icu::UnicodeString(self.UTF8String);
    }
    
    @end
    
    
    

    external by sffc  2  0  1  0

    A GDB pretty-printer for ICU4C UnicodeStrings

    A GDB pretty-printer for ICU4C UnicodeStrings: icu_unicodestring_prettyprinter.py
    # To autoload this file into GDB, put the following line in ~/.gdbinit:
    #
    #     python execfile("/path/to/icu_unicodestring_prettyprinter.py")
    #
    # You can also run that line of code in the GDB console without adding it to ~/.gdbinit.
    
    from __future__ import print_function
    from array import array
    import re
    
    class UnicodeStringPrinter:
    	"""GDB pretty printer for ICU4C UnicodeString"""
    
    	def __init__(self, val):
    		self.val = val
    
    	def to_string(self):
    		fLengthAndFlags = self.val["fUnion"]["fFields"]["fLengthAndFlags"]
    
    		if fLengthAndFlags >= 0:
    			# Short length
    			length = fLengthAndFlags >> 5
    		else:
    			# Long length
    			self.val["fUnion"]["fFields"]["fLength"]
    
    		if (fLengthAndFlags & 2) != 0:
    			# Stack storage
    			if (fLengthAndFlags & 1) != 0:
    				return u"UnicodeString (BOGUS)"
    			stack = True
    			buffer = self.val["fUnion"]["fStackFields"]["fBuffer"]
    		else:
    			# Heap storage
    			stack = False
    			buffer = self.val["fUnion"]["fFields"]["fArray"]
    
    		content = array('B', [buffer[i] for i in range(length)]).tostring()
    		return u"UnicodeString (%d on %s): \"%s\"" % (
    			length,
    			u"stack" if stack else u"heap",
    			content)
    
    unicode_string_re = re.compile("^icu_?\d*::UnicodeString$")
    
    def lookup_type(val):
    	# TODO: lookup_tag = val.type.tag
    	if unicode_string_re.match(str(val.type)):
    		return UnicodeStringPrinter(val)
    	return None
    
    gdb.pretty_printers.append(lookup_type)
    
    
    

    List Complete ( 3 snippets total )

    • Public Snippets
    • Channels Snippets