/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ /* PURPOSE * supposed to be used instead of std::string */ #include "mzstring.h" #ifdef _WIN32 # include #endif #include #include #include #ifndef _WIN32 # define wsprintf sprintf #endif const int AllocSize = 8; inline int get_alloc_size(int len) { return (len + AllocSize - 1) / AllocSize * AllocSize; } MzString::MzString() { Length = 0; Allocated = 0; Data = nullptr; } MzString::~MzString() { if (Data) free(Data); } MzString &MzString::operator=(const MzString &s) { int n = s.length(); if (allocate(n)) { if (n > 0) memcpy(Data, s.Data, n); Length = n; } return *this; } MzString &MzString::operator = (const char *s) { if (s == nullptr) s = ""; int n = strlen(s); if (allocate(n)) { if (n > 0) memcpy(Data, s, n); Length = n; } return *this; } void MzString::append(const char *s, int slen) { if(!s || slen <= 0) return; int new_len = Length + slen; if (allocate(new_len)) { memcpy(Data + Length, s, slen); Length = new_len; } } void MzString::append(MzString const &s) { if (s.Data) append(s.Data, s.length()); } void MzString::append(const char *s) { if (!s) return; append(s, strlen(s)); } int MzString::compare(const char *s) { if (!Data) return -1; if (s==nullptr) return 1; Data[Length] = 0; return strcmp(Data, s); } int MzString::find(char ch) { return find(ch,0); } int MzString::find(char ch, int pos) { for (int i = pos; i < Length; i++) { if (Data[i] == ch) return i; } return -1; } int MzString::rfind(char ch) { return rfind(ch, Length - 1); } int MzString::rfind(char ch, int pos) { if (pos >= Length) return -1; while (pos >= 0) { if (Data[pos] == ch) return pos; pos--; } return -1; } // << operator MzString &MzString::operator << (const char *str) { append(str); return *this; } MzString &MzString::operator << (char ch) { append(&ch, 1); return *this; } MzString &MzString::operator << (int i) { char str[80]; wsprintf(str, "%d", i); append(str); return *this; } MzString &MzString::operator << (long l) { char str[80]; wsprintf(str, "%ld", l); append(str); return *this; } MzString &MzString::operator << (MzString const &s) { append(s); return *this; } char MzString::operator [] (int n) { if (Data && 0 <= n && n < Length) return Data[n]; return 0; } void MzString::replace(int pos, char ch) { if (Data && 0 <= pos && pos < Length) Data[pos] = ch; } // Private Methods. bool MzString::allocate(int len) { len++; // In case we want to add a null. if (len < 0) return false; if (Data) { if (len < Allocated) return true; else { int n = get_alloc_size(len); char *p = static_cast(realloc(Data, n)); if (p) { Data = p; Allocated = n; return true; } } } else { // In case we want to add a null. int n = get_alloc_size(len); Data = static_cast(malloc(n)); if (Data) { Allocated = n; return true; } } return false; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ on value='distro/collabora/lov-5.0'>distro/collabora/lov-5.0 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
path: root/swext
AgeCommit message (Expand)Author
2014-02-22Resolves: fdo#75308 Asterisk at the beginning of Paragraph without "Nowiki"Julien Nabet
2014-02-19Resolves: fdo#69925 Wiki Publisher Extension is not workingJulien Nabet
2014-02-12Related: fdo#74875 Filter of "nowiki" to be improved - Export to MediaWikiJulien Nabet
2014-02-12normalize values of SYSTEM_APACHE_COMMONS, SYSTEM_BSHMichael Stahl
2014-02-11Resolves: fdo#74820 Failed to recognized Heading 6-Export to MediaWikiJulien Nabet
2014-02-06typo fixes in commentsAndras Timar
2013-11-04gbuild: fix gb_Extension_use_default_descriptionMichael Stahl
2013-10-26swext: fix wiki-publisher / apache-commons buildMichael Stahl
2013-10-25stop using apache-commons jars from OUTDIR tooMichael Stahl
2013-10-25stop looking for Jar files in solverMichael Stahl
2013-10-24xsltml: remove ExternalPackage, use files from WORKDIRMichael Stahl
2013-10-04Fix path for common-update.dtdJulien Nabet
2013-08-30ENABLE_MEDIAWIKI Harmonize ENABLE_* variable to TRUE/<nothing>Norbert Thiebaud
2013-07-11Resolves: #i121544# - Clean-up MessageBox APIAriel Constenla-Haile
2013-07-05Related: #i121513# Remove deprecated UnoControlThrobberModelAriel Constenla-Haile
2013-05-12Resolves: #i121907# upgrade odt2mediawiki to latest versionAriel Constenla-Haile
2013-04-30Move to MPLv2 license headers, with ESC decision and author's permission.Michael Meeks
2013-04-19Java cleanup in mediawiki extensionNoel Grandin
2013-04-17fdo#62096 - replace some O(U)String compareTo with ==Artur Dryomov