/* * This file part of makedict - convertor from any dictionary format to any * http://xdxf.sourceforge.net * Copyright (C) 2005-2006 Evgeniy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #include "utils.hpp" bool make_directory(const std::string& dir) { if (g_mkdir(dir.c_str(), 0700) && errno!=EEXIST) { std::cerr<<_("Can not create directory: ")<first; while (*p && *q && *p==*q) ++p, ++q; if (*q=='\0') { res+=i->second; break; } } if (i==replace_table.end()) { p=beg; res+=*p++; } } } std::vector split(const std::string& str, char sep) { std::vector res; std::string::size_type prev_pos=0, pos = 0; while ((pos=str.find(sep, prev_pos))!=std::string::npos) { res.push_back(std::string(str, prev_pos, pos-prev_pos)); prev_pos=pos+1; } res.push_back(std::string(str, prev_pos, str.length()-prev_pos)); return res; } std::string& strip(std::string& str) { std::string::size_type i; for (i=str.length(); i>0 && g_ascii_isspace(str[i-1]); --i) ; str.resize(i); for (i=0; i= 0; i--) { int tmp = b64_index[ (unsigned char)val[i] ]; #if 0 if (tmp == XX) err_internal( __FUNCTION__, "Illegal character in base64 value: `%c'\n", val[i] ); #endif v |= tmp << offset; offset += 6; } return v; } static unsigned char b64_list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* |b64_encode| encodes |val| in a printable base 64 format. A MSB-first encoding is generated. */ const char *b64_encode(guint32 val) { static char result[7]; int i; result[0] = b64_list[ (val & 0xc0000000) >> 30 ]; result[1] = b64_list[ (val & 0x3f000000) >> 24 ]; result[2] = b64_list[ (val & 0x00fc0000) >> 18 ]; result[3] = b64_list[ (val & 0x0003f000) >> 12 ]; result[4] = b64_list[ (val & 0x00000fc0) >> 6 ]; result[5] = b64_list[ (val & 0x0000003f) ]; result[6] = 0; for (i = 0; i < 5; i++) if (result[i] != b64_list[0]) return result + i; return result + 5; } void copy_file(const std::string& from, const std::string& to) { std::ifstream in(from.c_str(), std::ios::binary|std::ios::in); std::ofstream out(to.c_str(), std::ios::binary|std::ios::out|std::ios::trunc); char c; while (in.get(c)) out.put(c); }