More python unicode object support in ycm_core

This commit is contained in:
Strahinja Val Markovic 2013-09-07 12:33:01 -07:00
parent 3f0b719846
commit a7c609efd7
2 changed files with 12 additions and 4 deletions

View File

@ -27,6 +27,7 @@
using boost::algorithm::any_of;
using boost::algorithm::is_upper;
using boost::python::len;
using boost::python::str;
using boost::python::extract;
using boost::python::object;
typedef boost::python::list pylist;
@ -35,6 +36,13 @@ namespace YouCompleteMe {
namespace {
std::string GetUtf8String( const boost::python::object &string_or_unicode ) {
extract< std::string > to_string( string_or_unicode );
if ( to_string.check() )
return to_string();
return extract< std::string >( str( string_or_unicode ).encode( "utf8" ) );
}
std::vector< const Candidate * > CandidatesFromObjectList(
const pylist &candidates,
const std::string &candidate_property ) {
@ -44,10 +52,10 @@ std::vector< const Candidate * > CandidatesFromObjectList(
for ( int i = 0; i < num_candidates; ++i ) {
if ( candidate_property.empty() ) {
candidate_strings.push_back( extract< std::string >( candidates[ i ] ) );
candidate_strings.push_back( GetUtf8String( candidates[ i ] ) );
} else {
object holder = extract< object >( candidates[ i ] );
candidate_strings.push_back( extract< std::string >(
candidate_strings.push_back( GetUtf8String(
holder[ candidate_property.c_str() ] ) );
}
}

View File

@ -178,7 +178,7 @@ class Completer( object ):
self.completions_cache.filtered_completions = (
self.FilterAndSortCandidates(
self.completions_cache.raw_completions,
ToUtf8IfNeeded( request_data[ 'query' ] ) ) )
request_data[ 'query' ] ) )
else:
self.completions_cache = None
self.CandidatesForQueryAsyncInner( request_data )
@ -216,7 +216,7 @@ class Completer( object ):
matches = ycm_core.FilterAndSortCandidates(
candidates,
sort_property,
query )
ToUtf8IfNeeded( query ) )
return matches