w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How can I get pymongo to always return str and not unicode?
No, there is no such feature in PyMongo; every string decoded from BSON is decoded as UTF-8. Python represents the string internally as UCS-2 or some other format, depending on the Python version. See the code where the BSON decoder extracts a string. In the upcoming PyMongo 3.x series we may add features for more flexible BSON decoding to allow developers to optimize uncommon use cases like this.

Categories : Misc

LINQ FUNCTION TO RETURN LIST BUT COMPILER SAYS function doesn't return a value on all code path
All code paths don't return a value. If searchtype = "withdatetime" Then Dim locs As New crimemsapslocationDataContext Dim giveloc = From locations In locs.crimelocations _ Where locations.INCIDENTTYPE = crime And (locations.DATE_COMTD >= Convert.ToDateTime(startdate) And locations.DATE_COMTD <= Convert.ToDateTime(enddate)) _ And (locations.gettimecom >= starttime And locations.gettimecom <= endtime) _ Select locations Return giveloc.ToList ElseIf searchtype = "withdate" Then Dim locs As New crimemsapslocationDataContext Dim giveloc = From locations In locs.crimelocations _ Where locations.INCIDENTTYPE = crime And (locations.DATE_COMTD >= Conv

Categories : Asp Net

Ember.js - Return unicode character from computed property
I just created a simple jsbin: http://jsbin.com/izurix/5/edit Basically doing this does not return any &amp for me: App.ApplicationController = Ember.ObjectController.extend({ value: "&#61573;", someValue: function() { return new Handlebars.SafeString(this.get('value')); }.property('value') }); Furthermore if you don't want that handlebars escapes your string you should use triple-slash {{{someValue}}}. Hope it helps.

Categories : Ember Js

How to return plain text from Beautiful Soup instead of unicode
There is no such thing as plain text. What you see are bytes interpreted as text using incorrect character encoding i.e., the encoding of the strings is different from the one used by your terminal unless the error were introduced earlier by using incorrect character encoding for the web page. print x calls str(x) that returns UTF-8 encoded string for BeautifulSoup objects. Try: print unicode(x) Or: print x.encode('ascii')

Categories : Python

clojure jdbc postgres: Why do the results from my query return unicode characters in table names as �?
That's a classic sign of an encoding mismatch or something decoding already decoded / encoding already encoded data. When you're dealing with encoding problems you really have to trace what's happening step-by-step. This can be really tiresome I'm afraid. You need to identify every point at which an encoding conversion is done and find the one that's mangling the data or misinterpreting it. This can involve writing driver test cases, using alternative clients to examine data in-situ, etc. Another possibility is that the result is fine, but the tool you're using to display the result doesn't have an appropriate font; it's missing glyphs for the characters, so they show as placeholders. You should examine the character codes for the incorrect characters in the result - the actual binary

Categories : Postgresql

Is there a function that returns the UNICODE value of a character? (C++)
The question really doesn't make sense in the context of C++. You have to define what you mean by the Unicode value (which encoding format)—Java insists on UTF-16, but arguably UTF-8 or UTF-32 make more sense. Also, despite the name, the Java function does not change or reinterpret any values. It's the exact equivalent of wstring( 1, L'a' ) in C++, at least on machines where wchar_t is UTF-16. (In C++11, you can force UTF-16, with std::u16string( 1, u'a' ).)

Categories : C++

Returning unicode string from XLL function
When specifying the string length for the wide character string, the first wide character holds the length of the string. If it's purely cyrillic unicode this is 8 bytes, for just roman characters it'll be 4 bytes. So this should work: if (Reg == 0) {xResult.val.str = L"35Ошибка диапазона параметров";debugPrintf("Reg = 0");} See more here (see Table 2): http://msdn.microsoft.com/en-us/library/office/aa730920%28v=office.12%29.aspx

Categories : C++

UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode
You're passing the value returned by the FileField image directly into the response as if it were a string or iterable. Checking the source code for the exception path given, we see that the object returned by the field has the offending line in its __iter__ method - the wrapper class is looking for line terminators. It's certainly plausible that the raw image file could contain bytes that can't be converted to something that can be compared against the line terminator characters. The HttpResponse just needs something it can treat as a string - if you give it an iterator it reads it all in at once and creates a string, so there are no memory savings available: HttpResponse will consume the iterator immediately, store its content as a string, and discard it. https://docs.djangoproj

Categories : Python

SSIS Package: convert between unicode and non-unicode string data types
The Oracle data type VARCHAR2 appears to be equivalent to NCVARCHAR in SQL Server, or DT_WSTR in SSIS. Reference You will have to convert using the Data Conversion Transformation, or CAST or CONVERT functions in SQL Server.

Categories : Sql Server

Replace unicode number between to different delimiters with NCHAR function
I've solved the problem with this query: declare @position int, @txt nvarchar(max), @output as nvarchar(max), @buffer as varchar(max); set @position=1; set @txt = '#2361;#2367;#2344;#2381;#2342;#2368;abcde#32;fG#35;'; set @output = ''; set @buffer = ''; while @position <= len(@txt) begin declare @t varchar(max); select @t=(substring(@txt,@position,1)) if ( len(@buffer) = 0 and @t <> '#' and @t <> ';') BEGIN -- Append simple chars, which were not encoded Print 'Hänge den String ganz normal an den Output: ' + @t SET @output = @output + @t; END ELSE BEGIN if ( @t = '#' ) BEGIN Print 'Raute wurde erkannt: #'; SET @buffer = '#'; END else if ( @t = ';' ) BE

Categories : Sql Server

How do I know all supported encodings recognized by Python's unicode function
Here is a list for python 2.7 also you can do this from encodings.aliases import aliases >>> def find(q): q = encodings.normalize_encoding(q) ... return [(k,v)for k,v in aliases.iteritems() if q in v or q in k] >>>> find('100') [('ksx1001', 'euc_kr'), ('iso_ir_100', 'latin_1'), ('ks_x_1001', 'euc_kr')]

Categories : Python

Is there a function to decode encoded unicode utf-8 string like from a form?
I have a library called AltWebForm that en/decodes percent-encoded web form data: do http://reb4.me/r3/altwebform load-webform "field=%E4%BA%BA" The library is described here: Rebol and Web Forms.

Categories : Forms

Setting Proxy URL with unicode characters using InternetSetOption function
InternetSetOption is a fairly normal Win32 function. It is available in two flavours, the ANSI and Unicode versions. The need for these different versions comes from the fact that Windows 95/98/ME did not support Unicode and only had support for 8 bit encodings. Since you can safely ignore those ancient versions of Windows, you can use the Unicode versions of the Win32 API. In your case this means that you make sure that you compile your application to target Unicode. This will make sure that InternetSetOption is mapped to InternetSetOptionW, the Unicode version which uses the UTF-16 encoding. Your character arrays should use the Windows 16 bit character type wchar_t as the base character type. You must not use char because that is 8 bit. I'm not sure that this change will resolve your

Categories : C

Accessing the original value of the unicode string when subclassing unicode
Since you a subclassing unicode, instances of SufficComparingUnicodeString can usually be used just like any other Unicode string. So you can just use other.endswith(self) in your __eq__() implementation: class SuffixComparingUnicodeString(unicode): def __eq__(self, other): return isinstance(other, unicode) and other.endswith(self)

Categories : Python

How to deal with a mix of unicode- and non-unicode projects in Visual Studio
From your description it seems like you own those libraries. I would change them to use "Using Generic-Text Mappings" http://msdn.microsoft.com/en-us/library/7dzey6h6.aspx That way you can compiled them with UNICODE and _UNICODE defined for Windows, and without that on other systems. You will have to write something like your own tchar.h though (but pretty trivial, just a bunch of ifdefs to map _tprintf to wprintf/printf, for instance).

Categories : C++

Can changing a function which used to return a const ref to an std::string to return by value break calling code?
One way this could go wrong is if the calling code does something like: const char* s = ConvertToString(first).c_str(); And then stores s somewhere and accesses it later, thinking that the std::string object referenced by the return value of ConvertToString will never be destroyed. Of course, that calling code sucks anyway, in that case.

Categories : C++

How to handle "not all code paths return a value" when the logic of the function does ensure a return
C# code flow analysis is limited and as your sample points out there are cases where all paths do return but the compiler can't detect it. Throwing an exception is an acceptable remedy in those circumstances. I would not use a return of a default value to fix this error. You're operating under the assumption that the line is never hit against the advice of the compiler. Consider for a second that your analysis is wrong and execution can proceed to the end of the method. If you return a default value then you will have no indication of the problem. The method will just be returning bad data. Throwing an exception will make it very obvious that there is a problem. However in those cases my preference is to simply rewrite the code such that the compiler can see that all paths ter

Categories : C#

Decode Unicode chars in PHP by the unicode number
The behaviour you've found is exactly what's documented: This function is the opposite of htmlspecialchars(). It converts special HTML entities back to characters. The converted entities are: &amp;, &quot; (when ENT_NOQUOTES is not set), &#039; (when ENT_QUOTES is set), &lt; and &gt; You want some other related function, so we scroll down the documentation to the See Also section and find html_entity_decode(): Convert all HTML entities to their applicable characters var_dump( htmlspecialchars_decode('&#45;&#32;') ); var_dump( html_entity_decode('&#45;&#32;') ); string(10) "&#45;&#32;" string(2) "- "

Categories : PHP

Return a reference by a class function and return a whole object in c++?
First, the usual convention in C++ is to pass class type arguments as references to const. There are clearly exceptions (predicate objects or iterators in the standard library), but in application level code, passing a class type by reference to const is ubiquitous enough to justify a comment: Vector Vector::operator+( Vector const& rhs ) const { // ... } Or more likely: Vector operator+( Vector const& lhs, Vector const& rhs ) { Vector results( lhs ); results += rhs; return results; } Another widespread convention is to make such binary operators free functions, so that both the left and right arguments ar treated in the same fashion. And to implement them in terms of =, so as to ensure that = and have the desired relation. For operators which modify

Categories : C++

Matlab function switching return/no return
One common trick in matlab is to use the empty matrix [] to indicate nothing. You could write your function something like (untested code): function result = analyze(image, special_point) % your code here if pixels_are_ok result.a = 1; result.b = 2; else result = []; end If you call this function from your other code, you can use isempty to see if you got a result or not: result = analyze(image, special_point) if isempty(result) display('did not find anything') else display('found some interesting results') display(result) end

Categories : Matlab

Convert sql Non-Unicode parameter to Unicode
Try create procedure usp_GetPersonsWhoseNameContains(@LN nvarchar(50)) as begin select * from Person where Lastname like N'%'+@LN+'%' end declare @LastName nvarchar(50) = N'ی' exec usp_GetPersonsWhoseNameContains(@LastName) Maybe you noticed that SQL Server uses N to any quoted string input when generating DDL scripts for you.

Categories : SQL

2.7 CSV module wants unicode, but doesn't want unicode
Unfortunately, 3to2 used the io.open() call instead of the built-in Python 2 open() function. This opened the file in text mode, which like on Python 3 expects Unicode input. However, the csv module does not support Unicode data; it certainly does not produce Unicode. You'll either have to open the file in binary mode on Python 2: mode = 'w' if sys.version_info.major < 3: mode += 'b' csvfile_ = open(finishedFileName + num + ".csv", mode, newline='') or use the built-in open() call instead: csvfile_ = open(finishedFileName + num + ".csv", 'wb') where you have to use 'wb' as the mode anyway. If you are trying to write out unicode data, you'll have to encode that data before passing it to the csv.writer() object. The csv module examples section includes code to make encoding f

Categories : Python

Postgresql and unicode table names: Why can I not select the table name from the information schema when it contains unicode characters?
It looks like a bug, perhaps in regclass or something related to it: # create table pinkƒpink1 (id serial); NOTICE: CREATE TABLE will create implicit sequence "pink?pink1_id_seq" for serial column "pink?pink1.id" CREATE TABLE # select 'pinkƒpink1'::name; name ------------ pinkƒpink1 (1 row) # select 'pinkƒpink1'::regclass; regclass ------------- "pinkpink1" (1 row) # select relname from pg_class where oid = 'pinkƒpink1'::regclass; relname ----------- pinkpink1 # select relname from pg_class where relname = 'pinkƒpink1'::name; relname --------- (0 rows) # select relname from pg_class where relname = 'pinkpink1'; relname --------- (0 rows) (My system is OSX Lion with everything utf8, in case it matters.) For the workaround, you can cast it to ::regcla

Categories : Osx

how can find return variable value outside anonymous function in node js mysql query function
Try this and define the scope of variable as global     DBDATA=""; var alldata = function(){ var http = require('http'), mysql = require('mysql'); var client = mysql.createConnection({ host: '127.0.0.1', user: 'root', password: '' }); client.connect(); client.query("use cakephp2"); client.query("SELECT id, title,body,created from posts", function(err, results, fields) { if (err) throw err; var output = '<h1>Latest Posts</h1><ul><table border=1><tr>'; for (var index in fields) { output += '<td>' + fields[index].name + '</td>'; } output += '</tr>'; for (var index in results) { output += '<tr><td>' +

Categories : Javascript

In what Javascript engines does Function.prototype.toString not return the source code of that function?
What current Javascript engines don't behave this way? Your question isn't really well-defined, given that you haven't defined "popular". Is IE6 popular? IE5? IE4? Netscape Navigator? Lynx? The only way to properly answer your question is to enumerate which browsers you wish to support and check them. Unfortunately kangax's table http://kangax.github.io/es5-compat-table/# doesn't test Function.prototype.toString Chrome's console will even tell you (when you pass anything other than a function o Function.toString.call), that Function.prototype.toString is not generic mandated in the spec the spec refrains from making any commitment as to what the behaviour should be when applied to functions The required behavior is specified in ECMA-262 version 1 (from 1997, http://

Categories : Javascript

JavaScript - override a function with a function that contains async callbacks and still return original value
callNextMiddleware should return its recursive call's return value, not middlewareFunc's. if (middlewareFunc) { var result; middlewareFunc.call(this, function() { result = callNextMiddleware(middlewares, callback); }); return result; } Fiddle: http://jsfiddle.net/mWGXs

Categories : Javascript

calling function should return default value, if object (or any function result) is null
Not really, any code you would write this way would look horrible and/or use very slow reflection. Unless you use an actual Java preprocessor that can understand and change the code you've written. A better (but associated with quite a bit of refactoring) approach would be to make sure that the values in question cannot possibly be null. For example, you could modify the individual accessors (getSubObject(), getDesiredValue()) to never return null in the first place: make them return default values. The accessors on the default values return default values in turn.

Categories : Java

how to return a value from inner function that have a phonegap database SQLite query to the outer function
The problem is very clear, as you are using heavy process(i.e. database) inside a function so jquery runs this function in seperate thread parallel to your main thread now in this condition your value will always get undefined. you can make a global variable var hasSubAcc=-1; now after checking condition if(rs.rows.length == 0) { hasSubAcc=0; } else { hasSubAcc=1; } now give a small delay using setTimeout(function(){ alert(hasSubAcc); },500); or while(hasSubAcc==-1){ //do nothing } alert(hasSubAcc);

Categories : Javascript

Rspec to mock my call to external api from my function and return custom response back to the function
Checkout https://github.com/bblimke/webmock or http://fakeweb.rubyforge.org/ Then you do something like: stub_request( :post, "#{GITHUB_URL}1.json" ).to_return( body: { actor_attributes: {name: "Bill"} }.to_json ) I'm a bigger fan of Webmock than Fakeweb (it's got a few more features), but they'll both do for you, and it's pretty easy to switch between them.

Categories : Ruby On Rails

What should the return type be when the function might not have a value to return?
What would be the most elegant modern C++ way? There's, as always, not just one solution to this problem. If you decide to go for any solution that references the original resonse instance, you're on a slippery road when it comes to aliasing and memory management, especially in a multi threaded environment. By copying the response to the caller, no such issues arises. Today, I would do this: std::unique_ptr<std::string> find_response(const std::string& id) const; That way, you can check for nullptr as "in the olden days" and it's 100% clear who's responsibility it is to clear up the returned instance: the caller. The only downside I see of this, is the additional copy of the response string, but don't dismiss that as a downside until measured and proven so. Another wa

Categories : C++

return variable name from outside of function, as string inside python function
You cannot pass a variable as a string*, and you should not do so. If you want to pass a value between functions, the normal way is to pass it in as a parameter, and out as a return value. If that is inconvenient, the usual solution is an object: define a class which carries both the shared variable, and methods which act on the variable. If you need to create command objects, it is much better to do so in a structured way. For example, if you want to pass a function, and parameters, you can literally just pass the function object and the parameters in a tuple: def foo(): return (functionONE,somearray,1,3) command = foo() command[0](*command[1:]) If you want to embed such commands within commands, you'll likely want to wrap that up with a class, so you can recursively evaluate

Categories : Python

Does ember.js function.property() always succeed a function with a return statement?
You need to see a property as a attribute. Ember doesn't make a distinction between functions and attributes. If you have a property it must return a value, since it acts like an attribute. If you're looking not to return a value, but you want something to change based on another property, you'd use the observable pattern. Have a look in the guide for more information.

Categories : Ember Js

How to execute the function return the value to called function across node js files
Unable to send the variable resourceIdentifiers from subscriptionRestService to mysqlRestService.js Well, you didn't send it. It currently is a parameter of your callback function in the invocation, not an argument for the parameter of getPricingDetails. Use mysql.getPricingDetail(resourceIdentifiers, function callback(result){ // use result here }); Unable to return the pricingdetail from mysqlRestService.js to calling function in subscriptionRestService. I've got no idea what pricingDetail = pricingDetail; was supposed to do. You have to call (invoke) back the callback here! Use callback(pricingDetail);

Categories : Javascript

C pass address of a function return value as function parameter
No you can't do that in C. Also note C doesn't have something called as reference as in C++. For that C has pointers to achieve the same behaviour.. To achieve the same goal in C use temporary variable like, int val; val = b(); a( &val ); // & is called as "address of" operator in C To answer why there is no reference in C, from my understanding pointer and reference are meant to achieve the same goal - minimizing or avoiding data copy. For this C's pointer is good enough, though technically both have some difference in C++ (taken for reference)

Categories : C

how do i exit a function which causes segfault and return to calling function
Here's a similar question with an answer (albeit the wrong language, C++): Catch Segfault or any other errors/exceptions/signals in C++ like catching exceptions in Java I believe that what you're looking for is an exception in place of your exit(0) statement, but a Segmentation Fault is not an exception, therefore making it difficult to deal with. This being said, it appears that C does not have built in exception handling. Regardless, here's a reference about receptions in c++: http://www.cplusplus.com/doc/tutorial/exceptions/ I don't know exactly how you're using the function you have here, but perhaps you can return a boolean instead of void, and return from the calling function if the boolean is true?

Categories : C

How to prevent default in a function if a function already return somethiing
You could add return false;: for(var i=0; i < 2; i++){ someNode.onclick = function(num){ return function(){ alert(num); return false; } }(i); } Or you could use e.preventDefault either: for(var i=0; i < 2; i++){ someNode.onclick = function(num){ return function(e){ e.preventDefault(); alert(num); } }(i); }

Categories : Javascript

Why does ngRepeat use a compile function, when all it does is return a linking function?
Thats the way the Directive Definition Object is defined: You could also do: compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, iElement, iAttrs, controller) { ... } } Check Directives documentation at http://docs.angularjs.org/guide/directive A compile function can have a return value which can be either a function or an object. returning a (post-link) function - is equivalent to registering the linking function via the link property of the config object when the compile function is empty. returning an object with function(s) registered via pre and post properties - allows you to control when a linking function should be called during the li

Categories : Angularjs

How to return a cursor from database function to another function in activity
we should open and close database before and after use of database public void insert() { db.open(); Cursor cr = db.Settings();//db is object of database if (cr == null) otd.insert_setting(value + "", save_path, option); else { otd.delete_setting(); otd.insert_setting(value + "", save_path, option); } db.close }

Categories : Android

In golang, how to return a slice of type int from a function to another function?
Change your chan make to this: make(chan []int) Or select an index of your []int to send on your chan int. Either way int and []int are distinct types, as chan int and chan []int are.

Categories : Go

Have function return request data + a function to execute
How about Edit xmlhttp.onreadystatechange = (function(xmlhttp, url, somevar1, somevar2){ return function() { cfunc.call(this, xmlhttp, url, somevar1, somevar2); } })(xmlhttp, url, somevar1, somevar2);

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.