//---------------------------------------------------------------------------------------------------------------------- // // AC_OutputStream : an abstract output stream class // // This file is part of libpm library // // Copyright (C) 1997, ..., 2022 Pierre Molinaro. // // e-mail : pierre@pcmolinaro.name // // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 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 it will be useful, but WITHOUT ANY WARRANTY; without even the implied // warranty of MERCHANDIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details. // //---------------------------------------------------------------------------------------------------------------------- #include "streams/AC_OutputStream.h" #include "strings/C_String.h" #include "strings/unicode_character_cpp.h" #include "strings/unicode_string_routines.h" //---------------------------------------------------------------------------------------------------------------------- #include #include #define __STDC_FORMAT_MACROS // This is required for GCC for windows #include //---------------------------------------------------------------------------------------------------------------------- AC_OutputStream::AC_OutputStream (void) : mIndentation (0), mStartingLine (true) { } //---------------------------------------------------------------------------------------------------------------------- AC_OutputStream::~AC_OutputStream (void) { } //---------------------------------------------------------------------------------------------------------------------- void AC_OutputStream::flush (void) { } //---------------------------------------------------------------------------------------------------------------------- void AC_OutputStream::appendCString (const char * inCstring) { if (inCstring != NULL) { genericCharArrayOutput (inCstring, (int32_t) (strlen (inCstring) & UINT32_MAX)) ; } } //---------------------------------------------------------------------------------------------------------------------- void AC_OutputStream::genericCharArrayOutput (const char * inCharArray, const int32_t inArrayCount) { if (mIndentation == 0) { performActualCharArrayOutput (inCharArray, inArrayCount) ; }else if (inArrayCount > 0) { for (int32_t i=0 ; i 0) { for (int32_t i=0 ; i inLineMaxLength) { ioStream << "\"\n \"" ; currentColumn = 0 ; } currentColumn ++ ; const utf32 c = inString (i COMMA_HERE) ; switch (UNICODE_VALUE (c)) { case '\0' : break ; case '\a' : ioStream << "\\a" ; break ; case '\b' : ioStream << "\\b" ; break ; case '\f' : ioStream << "\\f" ; break ; case '\n' : ioStream << "\\n" ; if (i < (inStringLength - 1)) { ioStream << "\"\n \"" ; currentColumn = 1 ; } break ; case '\r' : ioStream << "\\r" ; break ; case '\t' : ioStream << "\\t" ; break ; case '\v' : ioStream << "\\v" ; break ; case '\\' : ioStream << "\\\\" ; break ; case '\"' : ioStream << "\\\"" ; break ; case '\?' : ioStream << "\\?" ; break ; default : if ((UNICODE_VALUE (c) >= ' ') && (UNICODE_VALUE (c) < 127)) { ioStream.appendUnicodeCharacter (c COMMA_HERE) ; }else{ char buffer [5] ; const int32_t n = UTF8StringFromUTF32Character (c, buffer) ; for (int32_t j=0 ; j= ' ') && (UNICODE_VALUE (c) <= '~')) { appendCString ("'") ; appendUnicodeCharacter (c COMMA_HERE) ; appendCString ("'") ; }else{ appendUnsigned (UNICODE_VALUE (c)) ; } break ; } } //---------------------------------------------------------------------------------------------------------------------- void AC_OutputStream::appendFileHeaderComment (const C_String & inLineCommentPrefix, const C_String & inTitle, const C_String & in_generatedBy_subtitle, const bool inIncludeLGPLtext) { if (inLineCommentPrefix.length () > 0) { appendCppHyphenLineCommentWithoutExtraBlankLine () ; appendCppSpaceLineComment () ; appendCppCenterJustifiedComment (inTitle) ; C_String subTitle ; if (in_generatedBy_subtitle.length () != 0) { subTitle << "Generated by " << in_generatedBy_subtitle ; appendCppCenterJustifiedComment (subTitle) ; subTitle.setLengthToZero () ; } C_DateTime today ; subTitle << today ; appendCppCenterJustifiedComment (subTitle) ; if (inIncludeLGPLtext) { appendCppSpaceLineComment () ; *this << inLineCommentPrefix << " This file is free software; you can redistribute it and/or modify it \n" << inLineCommentPrefix << " under the terms of the GNU Lesser General Public License as published \n" << inLineCommentPrefix << " by the Free Software Foundation; either version 2 of the License, or \n" << inLineCommentPrefix << " (at your option) any later version. \n" << inLineCommentPrefix << " \n" << inLineCommentPrefix << " This file is distributed in the hope it will be useful, but WITHOUT \n" << inLineCommentPrefix << " ANY WARRANTY; without even the implied warranty of MERCHANDIBILITY or \n" << inLineCommentPrefix << " FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public \n" << inLineCommentPrefix << " License for more details. \n" << inLineCommentPrefix << " \n" << inLineCommentPrefix << " You should have received a copy of the GNU General Public License along \n" << inLineCommentPrefix << " with this program; if not, write to the Free Software Foundation \n" << inLineCommentPrefix << " Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \n" ; } appendCppSpaceLineComment () ; appendCppHyphenLineComment () ; } } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cStringWithUnsigned #endif //---------------------------------------------------------------------------------------------------------------------- C_String cStringWithUnsigned (const uint64_t inValue) { C_String result ; result.appendUnsigned (inValue) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cHexStringWithUnsigned #endif //---------------------------------------------------------------------------------------------------------------------- C_String cHexStringWithUnsigned (const uint64_t inValue) { char s [32] ; snprintf (s, 32, "0x%" PRIx64, inValue) ; C_String result = s ; return result ; } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cStringWithSigned #endif //---------------------------------------------------------------------------------------------------------------------- C_String cStringWithSigned (const int64_t inValue) { C_String result ; result.appendSigned (inValue) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cStringWithCharacter #endif //---------------------------------------------------------------------------------------------------------------------- C_String cStringWithCharacter (const char inValue) { C_String result ; result.appendUnicodeCharacter (TO_UNICODE ((uint32_t) inValue) COMMA_HERE) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cStringWithUnicodeCharacter #endif //---------------------------------------------------------------------------------------------------------------------- C_String cStringWithUnicodeCharacter (const utf32 inValue) { C_String result ; result.appendUnicodeCharacter (inValue COMMA_HERE) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cStringWithPointer #endif //---------------------------------------------------------------------------------------------------------------------- C_String cStringWithPointer (const void * inValue) { C_String result ; result.appendPointer (inValue) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- #ifdef PRAGMA_MARK_ALLOWED #pragma mark cStringWithDouble #endif //---------------------------------------------------------------------------------------------------------------------- C_String cStringWithDouble (const double inValue) { C_String result ; result.appendDouble (inValue) ; return result ; } //----------------------------------------------------------------------------------------------------------------------