# HG changeset patch
# User Neil <nyamatongwe@gmail.com>
# Date 1520647909 -39600
#      Sat Mar 10 13:11:49 2018 +1100
# Node ID e84a1ec0a6b3745f154365ab534b8177946d6d52
# Parent  8d8bb42dee442a7b56c8cec0c7002785ff314862
Add SC_DOCUMENTOPTION_TEXT_LARGE option for documents larger than 2 GigaBytes.

diff -r 8d8bb42dee44 -r e84a1ec0a6b3 doc/ScintillaDoc.html
--- a/doc/ScintillaDoc.html	Fri Mar 09 21:34:57 2018 +1100
+++ b/doc/ScintillaDoc.html	Sat Mar 10 13:11:49 2018 +1100
@@ -119,7 +119,7 @@
 
     <h1>Scintilla Documentation</h1>
 
-    <p>Last edited 1 February 2018 NH</p>
+    <p>Last edited 20 February 2018 NH</p>
 
     <p>There is <a class="jump" href="Design.html">an overview of the internal design of
     Scintilla</a>.<br />
@@ -5746,10 +5746,11 @@
     <p id="documentOption">The <code class="parameter">documentOption</code> argument
     chooses between different document capabilities which affect memory allocation and performance with
     <code>SC_DOCUMENTOPTION_DEFAULT</code> (0) choosing standard options.
-    <code>SC_DOCUMENTOPTION_STYLES_NONE</code> (1) stops allocation of memory to style characters
+    <code>SC_DOCUMENTOPTION_STYLES_NONE</code> (0x1) stops allocation of memory to style characters
     which saves significant memory, often 40% with the whole document treated as being style 0.
-    Lexers may still produce visual styling by using indicators.</p>
-
+    Lexers may still produce visual styling by using indicators.
+    <code>SC_DOCUMENTOPTION_TEXT_LARGE</code> (0x100) accomodates documents larger than 2 GigaBytes.
+    </p>
     <table class="standard" summary="Document options">
       <tbody>
         <tr>
@@ -5769,10 +5770,16 @@
 
         <tr>
           <td align="left">SC_DOCUMENTOPTION_STYLES_NONE</td>
-          <td align="left">1</td>
+          <td align="left">0x1</td>
           <td align="left">Stop allocation of memory for styles and treat all text as style 0.</td>
         </tr>
 
+        <tr>
+          <td align="left">SC_DOCUMENTOPTION_TEXT_LARGE</td>
+          <td align="left">0x100</td>
+          <td align="left">Allow document to be larger than 2 GB.</td>
+        </tr>
+
       </tbody>
     </table>
 
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 doc/ScintillaHistory.html
--- a/doc/ScintillaHistory.html	Fri Mar 09 21:34:57 2018 +1100
+++ b/doc/ScintillaHistory.html	Sat Mar 10 13:11:49 2018 +1100
@@ -558,6 +558,9 @@
 	<a href="http://sourceforge.net/p/scintilla/bugs/1952/">Bug #1952</a>.
 	</li>
 	<li>
+	Add SC_DOCUMENTOPTION_TEXT_LARGE option to accomodate documents larger than 2 GigaBytes.
+	</li>
+	<li>
 	For rectangular selections, pressing Home or End now moves the caret to the Home or End
 	position instead of the limit of the rectangular selection.
 	</li>
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 include/Scintilla.h
--- a/include/Scintilla.h	Fri Mar 09 21:34:57 2018 +1100
+++ b/include/Scintilla.h	Sat Mar 10 13:11:49 2018 +1100
@@ -690,7 +690,8 @@
 #define SCI_SETZOOM 2373
 #define SCI_GETZOOM 2374
 #define SC_DOCUMENTOPTION_DEFAULT 0
-#define SC_DOCUMENTOPTION_STYLES_NONE 1
+#define SC_DOCUMENTOPTION_STYLES_NONE 0x1
+#define SC_DOCUMENTOPTION_TEXT_LARGE 0x100
 #define SCI_CREATEDOCUMENT 2375
 #define SCI_ADDREFDOCUMENT 2376
 #define SCI_RELEASEDOCUMENT 2377
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 include/Scintilla.iface
--- a/include/Scintilla.iface	Fri Mar 09 21:34:57 2018 +1100
+++ b/include/Scintilla.iface	Sat Mar 10 13:11:49 2018 +1100
@@ -1773,7 +1773,8 @@
 
 enu DocumentOption=SC_DOCUMENTOPTION_
 val SC_DOCUMENTOPTION_DEFAULT=0
-val SC_DOCUMENTOPTION_STYLES_NONE=1
+val SC_DOCUMENTOPTION_STYLES_NONE=0x1
+val SC_DOCUMENTOPTION_TEXT_LARGE=0x100
 
 # Create a new document object.
 # Starts with reference count of 1 and not selected into editor.
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 scripts/HeaderOrder.txt
--- a/scripts/HeaderOrder.txt	Fri Mar 09 21:34:57 2018 +1100
+++ b/scripts/HeaderOrder.txt	Sat Mar 10 13:11:49 2018 +1100
@@ -27,6 +27,7 @@
 #include <ctime>
 #include <cmath>
 #include <climits>
+#include <cinttypes>
 
 // C++ standard library
 #include <stdexcept>
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/CellBuffer.cxx
--- a/src/CellBuffer.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/CellBuffer.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -364,12 +364,15 @@
 	currentAction++;
 }
 
-CellBuffer::CellBuffer(bool hasStyles_) :
-	hasStyles(hasStyles_) {
+CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) :
+	hasStyles(hasStyles_), largeDocument(largeDocument_) {
 	readOnly = false;
 	utf8LineEnds = 0;
 	collectingUndo = true;
-	plv.reset(new LineVector<Sci::Position>());
+	if (largeDocument)
+		plv.reset(new LineVector<Sci::Position>());
+	else
+		plv.reset(new LineVector<int>());
 }
 
 CellBuffer::~CellBuffer() {
@@ -556,6 +559,10 @@
 	readOnly = set;
 }
 
+bool CellBuffer::IsLarge() const {
+	return largeDocument;
+}
+
 void CellBuffer::SetSavePoint() {
 	uh.SetSavePoint();
 }
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/CellBuffer.h
--- a/src/CellBuffer.h	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/CellBuffer.h	Sat Mar 10 13:11:49 2018 +1100
@@ -108,6 +108,7 @@
 class CellBuffer {
 private:
 	bool hasStyles;
+	bool largeDocument;
 	SplitVector<char> substance;
 	SplitVector<char> style;
 	bool readOnly;
@@ -126,7 +127,7 @@
 
 public:
 
-	CellBuffer(bool hasStyles_);
+	CellBuffer(bool hasStyles_, bool largeDocument_);
 	// Deleted so CellBuffer objects can not be copied.
 	CellBuffer(const CellBuffer &) = delete;
 	void operator=(const CellBuffer &) = delete;
@@ -163,6 +164,7 @@
 
 	bool IsReadOnly() const;
 	void SetReadOnly(bool set);
+	bool IsLarge() const;
 
 	/// The save point is a marker in the undo stack where the container has stated that
 	/// the buffer was saved. Undo and redo can move over the save point.
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/Document.cxx
--- a/src/Document.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/Document.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -91,7 +91,7 @@
 }
 
 Document::Document(int options) :
-	cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0) {
+	cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0, (options & SC_DOCUMENTOPTION_TEXT_LARGE) != 0) {
 	refCount = 0;
 #ifdef _WIN32
 	eolMode = SC_EOL_CRLF;
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/Document.h
--- a/src/Document.h	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/Document.h	Sat Mar 10 13:11:49 2018 +1100
@@ -352,6 +352,7 @@
 	void ConvertLineEnds(int eolModeSet);
 	void SetReadOnly(bool set) { cb.SetReadOnly(set); }
 	bool IsReadOnly() const { return cb.IsReadOnly(); }
+	bool IsLarge() const { return cb.IsLarge(); }
 
 	void DelChar(Sci::Position pos);
 	void DelCharBack(Sci::Position pos);
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/EditView.cxx
--- a/src/EditView.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/EditView.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -12,6 +12,7 @@
 #include <cctype>
 #include <cstdio>
 #include <cmath>
+#include <cinttypes>
 
 #include <stdexcept>
 #include <string>
@@ -2332,7 +2333,7 @@
 			(ypos + vsPrint.lineHeight <= pfr->rc.bottom) &&
 			(visibleLine >= 0)) {
 			char number[100];
-			sprintf(number, "%d" lineNumberPrintSpace, lineDoc + 1);
+			sprintf(number, "%" PRIdPTR lineNumberPrintSpace, lineDoc + 1);
 			PRectangle rcNumber = rcLine;
 			rcNumber.right = rcNumber.left + lineNumberWidth;
 			// Right justify
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/MarginView.cxx
--- a/src/MarginView.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/MarginView.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -12,6 +12,7 @@
 #include <cctype>
 #include <cstdio>
 #include <cmath>
+#include <cinttypes>
 
 #include <stdexcept>
 #include <string>
@@ -370,7 +371,7 @@
 					if (firstSubLine) {
 						char number[100] = "";
 						if (lineDoc >= 0)
-							sprintf(number, "%d", lineDoc + 1);
+							sprintf(number, "%" PRIdPTR, static_cast<intptr_t>(lineDoc + 1));
 						if (model.foldFlags & (SC_FOLDFLAG_LEVELNUMBERS | SC_FOLDFLAG_LINESTATE)) {
 							if (model.foldFlags & SC_FOLDFLAG_LEVELNUMBERS) {
 								const int lev = model.pdoc->GetLevel(lineDoc);
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/Position.h
--- a/src/Position.h	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/Position.h	Sat Mar 10 13:11:49 2018 +1100
@@ -16,8 +16,8 @@
 
 namespace Sci {
 
-typedef int Position;
-typedef int Line;
+typedef ptrdiff_t Position;
+typedef ptrdiff_t Line;
 
 const Position invalidPosition = -1;
 
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 src/RunStyles.cxx
--- a/src/RunStyles.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/src/RunStyles.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -305,3 +305,5 @@
 
 template class Scintilla::RunStyles<int, int>;
 template class Scintilla::RunStyles<int, char>;
+template class Scintilla::RunStyles<ptrdiff_t, int>;
+template class Scintilla::RunStyles<ptrdiff_t, char>;
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 test/unit/testCellBuffer.cxx
--- a/test/unit/testCellBuffer.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/test/unit/testCellBuffer.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -25,8 +25,8 @@
 	const char sText[] = "Scintilla";
 	const Sci::Position sLength = static_cast<Sci::Position>(strlen(sText));
 
-	CellBuffer cb(true);
-	
+	CellBuffer cb(true, false);
+
 	SECTION("InsertOneLine") {
 		bool startSequence = false;
 		const char *cpChange = cb.InsertString(0, sText, static_cast<int>(sLength), startSequence);
diff -r 8d8bb42dee44 -r e84a1ec0a6b3 test/unit/testPartitioning.cxx
--- a/test/unit/testPartitioning.cxx	Fri Mar 09 21:34:57 2018 +1100
+++ b/test/unit/testPartitioning.cxx	Sat Mar 10 13:11:49 2018 +1100
@@ -49,7 +49,7 @@
 
 TEST_CASE("Partitioning") {
 
-	Partitioning<int> part(growSize);
+	Partitioning<Sci::Position> part(growSize);
 
 	SECTION("IsEmptyInitially") {
 		REQUIRE(1 == part.Partitions());
