/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
Could make this inline
----------------------------------------------------------------------------*/ staticconstchar* GetLinebreakString(
nsLinebreakConverter::ELinebreakType aBreakType) { staticconstchar* const sLinebreaks[] = {"", // any
NS_LINEBREAK, // platform
LFSTR, // content
CRLF, // net
CRSTR, // Mac
LFSTR, // Unix
CRLF, // Windows " ", // space
nullptr};
ioLen *includes* a terminating null, if any
----------------------------------------------------------------------------*/ template <class T> static T* ConvertBreaks(const T* aInSrc, int32_t& aIoLen, constchar* aSrcBreak, constchar* aDestBreak) {
NS_ASSERTION(aInSrc && aSrcBreak && aDestBreak, "Got a null string");
T* resultString = nullptr;
// handle the no conversion case if (nsCRT::strcmp(aSrcBreak, aDestBreak) == 0) {
resultString = (T*)malloc(sizeof(T) * aIoLen); if (!resultString) { return nullptr;
}
memcpy(resultString, aInSrc, sizeof(T) * aIoLen); // includes the null, if any return resultString;
}
// handle the easy case, where the string length does not change, and the // breaks are only 1 char long, i.e. CR <-> LF if (srcBreakLen == destBreakLen && srcBreakLen == 1) {
resultString = (T*)malloc(sizeof(T) * aIoLen); if (!resultString) { return nullptr;
}
const T* src = aInSrc; const T* srcEnd = aInSrc + aIoLen; // includes null, if any
T* dst = resultString;
char srcBreakChar = *aSrcBreak; // we know it's one char long already char dstBreakChar = *aDestBreak;
Convert breaks in situ. Can only do this if the linebreak length does not change.
----------------------------------------------------------------------------*/ template <class T> staticvoid ConvertBreaksInSitu(T* aInSrc, int32_t aInLen, char aSrcBreak, char aDestBreak) {
T* src = aInSrc;
T* srcEnd = aInSrc + aInLen;
while (src < srcEnd) { if (*src == aSrcBreak) {
*src = aDestBreak;
}
Convert unknown line breaks to the specified break.
This will convert CRLF pairs to one break, and single CR or LF to a break.
----------------------------------------------------------------------------*/ template <class T> static T* ConvertUnknownBreaks(const T* aInSrc, int32_t& aIoLen, constchar* aDestBreak) { const T* src = aInSrc; const T* srcEnd = aInSrc + aIoLen; // includes null, if any
// nothing to do if (aIoString.IsEmpty()) { return NS_OK;
}
nsresult rv;
// remember the old buffer in case // we blow it away later
char16_t* stringBuf = aIoString.BeginWriting(mozilla::fallible); if (!stringBuf) { return NS_ERROR_OUT_OF_MEMORY;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.