1 /* 2 ============================================================================== 3 4 This file is part of the JUCE library. 5 Copyright (c) 2020 - Raw Material Software Limited 6 7 JUCE is an open source library subject to commercial or open-source 8 licensing. 9 10 The code included in this file is provided under the terms of the ISC license 11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission 12 To use, copy, modify, and/or distribute this software for any purpose with or 13 without fee is hereby granted provided that the above copyright notice and 14 this permission notice appear in all copies. 15 16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER 17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE 18 DISCLAIMED. 19 20 ============================================================================== 21 */ 22 23 namespace juce 24 { 25 26 //============================================================================== 27 /** This class is used for represent a new-line character sequence. 28 29 To write a new-line to a stream, you can use the predefined 'newLine' variable, e.g. 30 @code 31 myOutputStream << "Hello World" << newLine << newLine; 32 @endcode 33 34 The exact character sequence that will be used for the new-line can be set and 35 retrieved with OutputStream::setNewLineString() and OutputStream::getNewLineString(). 36 37 @tags{Core} 38 */ 39 class JUCE_API NewLine 40 { 41 public: 42 /** Returns the default new-line sequence that the library uses. 43 @see OutputStream::setNewLineString() 44 */ getDefault()45 static const char* getDefault() noexcept { return "\r\n"; } 46 47 /** Returns the default new-line sequence that the library uses. 48 @see getDefault() 49 */ String()50 operator String() const { return getDefault(); } 51 52 /** Returns the default new-line sequence that the library uses. 53 @see OutputStream::setNewLineString() 54 */ StringRef()55 operator StringRef() const noexcept { return getDefault(); } 56 }; 57 58 //============================================================================== 59 /** A predefined object representing a new-line, which can be written to a string or stream. 60 61 To write a new-line to a stream, you can use the predefined 'newLine' variable like this: 62 @code 63 myOutputStream << "Hello World" << newLine << newLine; 64 @endcode 65 */ 66 extern NewLine newLine; 67 68 //============================================================================== 69 /** Writes a new-line sequence to a string. 70 You can use the predefined object 'newLine' to invoke this, e.g. 71 @code 72 myString << "Hello World" << newLine << newLine; 73 @endcode 74 */ 75 inline String& operator<< (String& string1, const NewLine&) { return string1 += NewLine::getDefault(); } 76 inline String& operator+= (String& s1, const NewLine&) { return s1 += NewLine::getDefault(); } 77 78 inline String operator+ (const NewLine&, const NewLine&) { return String (NewLine::getDefault()) + NewLine::getDefault(); } 79 inline String operator+ (String s1, const NewLine&) { return s1 += NewLine::getDefault(); } 80 inline String operator+ (const NewLine&, const char* s2) { return String (NewLine::getDefault()) + s2; } 81 82 } // namespace juce 83