text_base_types.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: text_base_types.cpp
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-plaintext.
00007  *
00008  * uds-plugin-plaintext is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-plaintext is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #include "log.h"
00028 #include "text_base_types.h"
00029 
00030 namespace text
00031 {
00032 
00033 Position::Position(unsigned int paragraph_index, unsigned int offset)
00034 : paragraph(paragraph_index),
00035   offset(offset)
00036 {
00037 }
00038 
00039 Position::Position(const std::string& from_string)
00040 {
00041     if (from_string == "")
00042     {
00043         paragraph = offset = 0;
00044     }
00045     else
00046     {
00047         if (2 != sscanf(from_string.c_str(), "txt://%d:%d", &paragraph, &offset))
00048         {
00049             // Invalid anchor.
00050             ERRORPRINTF("Invalid text anchor detected!");
00051             paragraph = offset = 0;
00052         }
00053     }
00054 }
00055 
00056 Position::~Position()
00057 {
00058 }
00059 
00060 std::string Position::to_string() const
00061 {
00062     char buf[32];
00063     g_snprintf(buf, 32, "txt://%d:%d", paragraph, offset);
00064     return std::string(buf);
00065 }
00066 
00067 }
00068 
00069 
Generated by  doxygen 1.6.2-20100208