Skip to content

Commit

Permalink
Clean up anjuta-token-list
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Dec 13, 2009
1 parent 91608ba commit 8fc54f8
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 434 deletions.
130 changes: 64 additions & 66 deletions libanjuta/anjuta-token-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,72 +200,6 @@ anjuta_token_file_move (AnjutaTokenFile *file, GFile *new_file)
file->file = new_file != NULL ? g_object_ref (new_file) : NULL;
}

gboolean
anjuta_token_file_get_token_location (AnjutaTokenFile *file, AnjutaTokenFileLocation *location, AnjutaToken *token)
{
AnjutaTokenFileLocation loc = {NULL, 1, 1};
AnjutaToken *pos;
const gchar *target = anjuta_token_get_string (token);

for (pos = file->content; pos != NULL; pos = anjuta_token_next (pos))
{
if (!(anjuta_token_get_flags (pos) & ANJUTA_TOKEN_REMOVED) && (anjuta_token_get_length (pos)))
{
const gchar *ptr;
const gchar *end;

ptr = anjuta_token_get_string (pos);
end = ptr + anjuta_token_get_length (pos);

for (; ptr != end; ptr++)
{
if (*ptr == '\n')
{
/* New line */
loc.line++;
loc.column = 1;
}
else
{
loc.column++;
}

if (ptr == target)
{
if (location != NULL)
{
location->filename = file->file == NULL ? NULL : g_file_get_parse_name (file->file);
location->line = loc.line;
location->column = loc.column;
}

return TRUE;
}
}
}
}

return FALSE;
}


AnjutaToken*
anjuta_token_file_get_content (AnjutaTokenFile *file)
{
if (file->content == NULL)
{
anjuta_token_file_load (file, NULL);
}

return file->content;
}

GFile*
anjuta_token_file_get_file (AnjutaTokenFile *file)
{
return file->file;
}

/**
* anjuta_token_file_update:
* @file: a #AnjutaTokenFile derived class object.
Expand Down Expand Up @@ -406,6 +340,70 @@ anjuta_token_file_update (AnjutaTokenFile *file, AnjutaToken *token)
return TRUE;
}

gboolean
anjuta_token_file_get_token_location (AnjutaTokenFile *file, AnjutaTokenFileLocation *location, AnjutaToken *token)
{
AnjutaTokenFileLocation loc = {NULL, 1, 1};
AnjutaToken *pos;
const gchar *target = anjuta_token_get_string (token);

for (pos = file->content; pos != NULL; pos = anjuta_token_next (pos))
{
if (!(anjuta_token_get_flags (pos) & ANJUTA_TOKEN_REMOVED) && (anjuta_token_get_length (pos)))
{
const gchar *ptr;
const gchar *end;

ptr = anjuta_token_get_string (pos);
end = ptr + anjuta_token_get_length (pos);

for (; ptr != end; ptr++)
{
if (*ptr == '\n')
{
/* New line */
loc.line++;
loc.column = 1;
}
else
{
loc.column++;
}

if (ptr == target)
{
if (location != NULL)
{
location->filename = file->file == NULL ? NULL : g_file_get_parse_name (file->file);
location->line = loc.line;
location->column = loc.column;
}

return TRUE;
}
}
}
}

return FALSE;
}

GFile*
anjuta_token_file_get_file (AnjutaTokenFile *file)
{
return file->file;
}

AnjutaToken*
anjuta_token_file_get_content (AnjutaTokenFile *file)
{
if (file->content == NULL)
{
anjuta_token_file_load (file, NULL);
}

return file->content;
}

/* GObject functions
*---------------------------------------------------------------------------*/
Expand Down
6 changes: 3 additions & 3 deletions libanjuta/anjuta-token-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ gboolean anjuta_token_file_unload (AnjutaTokenFile *file);
gboolean anjuta_token_file_save (AnjutaTokenFile *file, GError **error);
void anjuta_token_file_move (AnjutaTokenFile *file, GFile *new_file);

gboolean anjuta_token_file_get_token_location (AnjutaTokenFile *file, AnjutaTokenFileLocation *location, AnjutaToken *token);

gboolean anjuta_token_file_update (AnjutaTokenFile *file, AnjutaToken *token);

AnjutaToken* anjuta_token_file_get_content (AnjutaTokenFile *file);
gboolean anjuta_token_file_get_token_location (AnjutaTokenFile *file, AnjutaTokenFileLocation *location, AnjutaToken *token);
GFile *anjuta_token_file_get_file (AnjutaTokenFile *file);
AnjutaToken *anjuta_token_file_get_content (AnjutaTokenFile *file);


G_END_DECLS

Expand Down
Loading

0 comments on commit 8fc54f8

Please sign in to comment.