Encoding data to utf8 if 'unicode' object

ycm_core only deals with utf8 and the functions only accept python string
objects.
This commit is contained in:
Strahinja Val Markovic 2013-09-07 11:58:42 -07:00
parent 29bb90a6b4
commit 3f0b719846
3 changed files with 12 additions and 3 deletions

View File

@ -19,6 +19,7 @@
import abc import abc
import ycm_core import ycm_core
from ycm.utils import ToUtf8IfNeeded
from ycm.completers.completer_utils import TriggersForFiletype from ycm.completers.completer_utils import TriggersForFiletype
NO_USER_COMMANDS = 'This completer does not define any commands.' NO_USER_COMMANDS = 'This completer does not define any commands.'
@ -177,7 +178,7 @@ class Completer( object ):
self.completions_cache.filtered_completions = ( self.completions_cache.filtered_completions = (
self.FilterAndSortCandidates( self.FilterAndSortCandidates(
self.completions_cache.raw_completions, self.completions_cache.raw_completions,
request_data[ 'query' ] ) ) ToUtf8IfNeeded( request_data[ 'query' ] ) ) )
else: else:
self.completions_cache = None self.completions_cache = None
self.CandidatesForQueryAsyncInner( request_data ) self.CandidatesForQueryAsyncInner( request_data )

View File

@ -22,6 +22,7 @@ import ycm_core
import logging import logging
from ycm import server_responses from ycm import server_responses
from ycm import extra_conf_store from ycm import extra_conf_store
from ycm.utils import ToUtf8IfNeeded
from ycm.completers.completer import Completer from ycm.completers.completer import Completer
from ycm.completers.cpp.flags import Flags from ycm.completers.cpp.flags import Flags
@ -109,8 +110,8 @@ class ClangCompleter( Completer ):
column = request_data[ 'start_column' ] + 1 column = request_data[ 'start_column' ] + 1
self.completions_future = ( self.completions_future = (
self.completer.CandidatesForQueryAndLocationInFileAsync( self.completer.CandidatesForQueryAndLocationInFileAsync(
query, ToUtf8IfNeeded( query ),
filename, ToUtf8IfNeeded( filename ),
line, line,
column, column,
files, files,
@ -369,3 +370,5 @@ def ClangAvailableForFiletypes( filetypes ):
def InCFamilyFile( filetypes ): def InCFamilyFile( filetypes ):
return ClangAvailableForFiletypes( filetypes ) return ClangAvailableForFiletypes( filetypes )

View File

@ -24,3 +24,8 @@ def IsIdentifierChar( char ):
def SanitizeQuery( query ): def SanitizeQuery( query ):
return query.strip() return query.strip()
def ToUtf8IfNeeded( string_or_unicode ):
if isinstance( string_or_unicode, unicode ):
return string_or_unicode.encode( 'utf8' )
return string_or_unicode