home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 24.3 KB | 794 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLCharIt.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef SLCHARIT_H
- #include "SLCharIt.h"
- #endif
-
- #ifndef PRCHARIT_H
- #include "PRCharIt.h"
- #endif
-
- #ifndef PRSTRREP_H
- #include "PRStrRep.h"
- #endif
-
- #ifndef SOM_FW_OTextRunReader_xh
- #include "SLTxtRun.xh"
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment Strings
- #endif
-
- //========================================================================================
- // Error handling strategy:
- //
- // This unit provides interfaces that are exported from a shared library.
- // As such, these interfaces must catch all exceptions and turn them into error codes.
- //
- // Most functions in this unit only call functions that are known to not throw exceptions.
- // For these functions, we do not use a try block, but instead simply check the error
- // codes and return if any error is seen during the execution of the function.
- //
- // A few functions in this unit do call functions that can throw exceptions. Two
- // possibilities must be considered:
- //
- // 1) The function calls a SOM member function. We assume that the SOM C++ binding will
- // invoke our SOMCHKEXCEPT which will throw an exception.
- //
- // 2) The function calls ::operator new. We assume that operator new will throw an
- // exception if the allocation fails.
- //
- // There should be no other way for exceptions to be raised. Functions defined here that
- // can raise exceptions via 1) or 2) above must be enclosed in a try block. We use the
- // FW_SOM_TRY macros which will convert the exception into an Environment error.
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // ByteInBlock
- //----------------------------------------------------------------------------------------
-
- inline FW_ByteCount BytesInBlock(const char* last, const char* first)
- {
- return last - first;
- }
-
- //----------------------------------------------------------------------------------------
- // PreviousByte
- //----------------------------------------------------------------------------------------
-
- inline const char* PreviousByte(const char* current, FW_ByteCount delta)
- {
- return current - delta;
- }
-
- //----------------------------------------------------------------------------------------
- // ClassInvariants
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_DEBUG
- static void ClassInvariants(FW_HTextReader self)
- {
- if (self->fNext == 0)
- {
- // Must be in initial state, before first GetNextBuffer
- FW_PRIV_ASSERT(self->fStart == 0);
- FW_PRIV_ASSERT(self->fLimit == 0);
- FW_PRIV_ASSERT(self->fBufferSum == 0);
- }
- else if (self->fNext == self->fLimit)
- {
- // Must be at end of data structure
- FW_PRIV_ASSERT(self->fBufferSum == self->fByteLength);
- }
- else
- {
- FW_PRIV_ASSERT(self->fBufferSum < self->fByteLength);
- if (self->fNext < self->fStart)
- {
- // Must be at position -1 (backup past beginning)
- FW_PRIV_ASSERT(self->fBufferSum == 0);
- FW_PRIV_ASSERT(self->fNext == self->fStart-1); // may not be correct anymore
- }
- else
- {
- // Must be somewhere in middle of stream
- FW_PRIV_ASSERT(self->fStart <= self->fNext);
- FW_PRIV_ASSERT(self->fNext <= self->fLimit);
- }
- }
- }
- #else
- inline void ClassInvariants(FW_HTextReader) {}
- // Let optimizer remove empty inline
- #endif
-
- //----------------------------------------------------------------------------------------
- // TextReader_Initialize
- //----------------------------------------------------------------------------------------
-
- static void TextReader_Initialize(FW_HTextReader self,
- Environment* ev,
- FW_OTextRunReader* adoptedReader)
- {
- FW_SOM_TRY
- {
- FW_ByteCount length;
- FW_Locale locale;
- const char* start = adoptedReader->GetCurrentRun(ev, &length, &locale); // may throw
- self->fLocale = locale;
- self->fReader = adoptedReader;
- self->fStart = start;
- self->fLimit = self->fStart+length;
- self->fNext = self->fStart;
- self->fByteLength = self->fReader->GetTotalLength(ev); // may throw
- ClassInvariants(self);
- }
- FW_SOM_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_Initialize
- //----------------------------------------------------------------------------------------
-
- FW_HTextReader FW_PrivTextReader_New(Environment* ev, FW_OTextRunReader* adoptedReader)
- {
- FW_SOM_TRY
- {
- FW_HTextReader self = new FW_SPrivTextReader; // may throw
- self->fReader = 0;
- self->fStart = 0;
- self->fLimit = 0;
- self->fNext = 0;
- self->fByteLength = 0;
- self->fBufferSum = 0;
- // self->fLocale.fScriptCode = 0;
- // self->fLocale.fLangCode = 0;
- self->fLocale = FW_PrivGetDefaultLocale();
- self->fRefCount = 0;
- TextReader_Initialize(self, ev, adoptedReader);
- return self;
- }
- FW_SOM_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_Acquire
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_Acquire(FW_HTextReader self, Environment* ev)
- {
- FW_UNUSED(ev);
- // No FW_SOM_TRY necessary
- ++self->fRefCount;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_Delete
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_Release(FW_HTextReader self, Environment* ev)
- {
- FW_UNUSED(ev);
- // No FW_SOM_TRY necessary
- if (--self->fRefCount == 0)
- delete self;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_GetCharacterAndAdvance
- //----------------------------------------------------------------------------------------
-
- FW_LChar FW_PrivTextReader_GetCharacterAndAdvance(FW_HTextReader self, Environment* ev, FW_ByteCount* bytesInChar)
- {
- // No FW_SOM_TRY necessary
- ClassInvariants(self);
- FW_ByteCount b;
- if (!bytesInChar)
- bytesInChar = &b;
- FW_LChar temp = FW_PrivTextReader_PeekCharacter(self, bytesInChar);
- if (temp != FW_kNulCharacter)
- FW_PrivTextReader_Advance(self, ev, *bytesInChar);
- ClassInvariants(self);
- return temp;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_Advance
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_Advance(FW_HTextReader self, Environment* ev, FW_ByteCount delta)
- {
- // No FW_SOM_TRY necessary
- ClassInvariants(self);
- FW_PRIV_ASSERT(delta>=0);
- FW_PRIV_ASSERT(delta+FW_PrivTextReader_GetPosition(self) <= self->fByteLength);
- FW_ByteCount inThisBuf = BytesInBlock(self->fLimit, self->fNext);
- while (delta >= inThisBuf)
- {
- delta -= inThisBuf;
- self->fNext += inThisBuf;
- FW_PrivTextReader_GetNextBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- inThisBuf = BytesInBlock(self->fLimit, self->fStart);
- }
- self->fNext += delta;
- ClassInvariants(self);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_PeekCharacter
- //----------------------------------------------------------------------------------------
-
- FW_LChar FW_PrivTextReader_PeekCharacter(FW_HTextReader self, FW_ByteCount* bytesInChar)
- {
- // No FW_SOM_TRY necessary, no error possible
- ClassInvariants(self);
-
- FW_Boolean singleByte = FW_LocaleIsSingleByte(self->fLocale);
- if (bytesInChar)
- *bytesInChar = 1; // default to single byte characters
-
- if (self->fNext >= self->fStart && self->fNext < self->fLimit)
- {
- FW_LChar ch = *self->fNext;
- if (singleByte)
- return ch;
-
- // Check for double-byte
- if (FW_CharIsDoubleByte(self->fNext, 0, self->fLocale))
- {
- ch = *((FW_LChar*)self->fNext);
- if (bytesInChar)
- *bytesInChar = 2;
- }
-
- return ch;
- }
- else
- return FW_kNulCharacter;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_GetPosition
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_PrivTextReader_GetPosition(FW_HTextReader self)
- {
- // No FW_SOM_TRY necessary, no error possible
- ClassInvariants(self);
- FW_ByteCount result;
-
- if (self->fNext == self->fLimit)
- result = self->fBufferSum;
- else
- result = self->fBufferSum + (self->fNext - self->fStart);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // DelegateGetNextBuffer
- //----------------------------------------------------------------------------------------
-
- static void DelegateGetNextBuffer(FW_HTextReader self, Environment* ev)
- {
- FW_SOM_TRY
- {
- FW_ByteCount length;
- if (self->fReader->NextRun(ev)) // may throw
- {
- FW_Locale locale;
- const char* start = self->fReader->GetCurrentRun(ev, &length, &locale); // may throw
- self->fStart = start;
- self->fLimit = start + length;
- self->fLocale = locale;
- }
- else
- {
- self->fStart = 0;
- self->fLimit = 0;
- }
- }
- FW_SOM_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_GetNextBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_GetNextBuffer(FW_HTextReader self, Environment* ev)
- {
- // No FW_SOM_TRY necessary
- // ClassInvariants won't hold here.
- // This function is called to (among other things) restore class invariants.
- FW_PRIV_ASSERT(self->fNext == self->fLimit); // Must hold, but violates invariants
- self->fBufferSum += BytesInBlock(self->fLimit, self->fStart);
- if (self->fBufferSum < self->fByteLength)
- {
- DelegateGetNextBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- self->fNext = self->fStart;
- }
- else
- {
- FW_PRIV_ASSERT(self->fBufferSum == self->fByteLength);
- self->fNext = self->fLimit;
- }
- ClassInvariants(self);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_BackupAndGetCharacter
- //----------------------------------------------------------------------------------------
-
- FW_LChar FW_PrivTextReader_BackupAndGetCharacter(FW_HTextReader self, Environment* ev, FW_ByteCount* bytesInChar)
- {
- // No FW_SOM_TRY necessary
- ClassInvariants(self);
-
- if (FW_LocaleIsSingleByte(self->fLocale))
- {
- FW_PrivTextReader_Backup(self, ev, 1);
- if (FW_GetEvError(ev))
- return 0;
- ClassInvariants(self);
- return FW_PrivTextReader_PeekCharacter(self, bytesInChar);
- }
- else
- {
- // probably double-byte, so back up 2 bytes
- FW_PrivTextReader_Backup(self, ev, 2);
- if (FW_GetEvError(ev))
- return 0;
-
- // check the character
- if (FW_PrivTextReader_PeekCharacterSize(self) == 2)
- return FW_PrivTextReader_PeekCharacter(self, bytesInChar);
-
- // either single-byte or 2nd of double-byte
- FW_PrivTextReader_Advance(self, ev, 1);
- if (FW_GetEvError(ev))
- return 0;
- ClassInvariants(self);
- return FW_PrivTextReader_PeekCharacter(self, bytesInChar);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_Backup
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_Backup(FW_HTextReader self, Environment* ev, FW_ByteCount delta)
- {
- // No FW_SOM_TRY necessary
- ClassInvariants(self);
- FW_PRIV_ASSERT(delta>=0);
- /* FW_PRIV_ASSERT(delta<=GetPosition()); * doesn't allow backup at start */
-
- if (delta > 0)
- {
- if (self->fNext==self->fStart) // at the start of a buffer
- {
- FW_PrivTextReader_GetPreviousBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- }
- else if (self->fNext == self->fLimit) // at the end of the last buffer
- { // subtract bytes that were added by GetNextBuffer
- self->fBufferSum -= BytesInBlock(self->fLimit, self->fStart);
- }
-
- FW_ByteCount inThisBuf = BytesInBlock(self->fNext, self->fStart);
- if (inThisBuf > 0)
- while (delta > inThisBuf)
- {
- delta -= inThisBuf;
- self->fNext = self->fStart;
- FW_PrivTextReader_GetPreviousBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- inThisBuf = BytesInBlock(self->fNext, self->fStart);
- }
- self->fNext = PreviousByte(self->fNext, delta); // may backup before fStart (-1)
- ClassInvariants(self);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // DelegateGetPreviousBuffer
- //----------------------------------------------------------------------------------------
-
- static void DelegateGetPreviousBuffer(FW_HTextReader self, Environment* ev)
- {
- FW_SOM_TRY
- {
- FW_ByteCount length;
- if (self->fReader->PreviousRun(ev)) // may throw
- {
- FW_Locale locale;
- const char* start = self->fReader->GetCurrentRun(ev, &length, &locale); // may throw
- self->fStart = start;
- self->fLimit = start+length;
- self->fLocale = locale;
- }
- else
- {
- self->fStart = 0;
- self->fLimit = 0;
- }
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_GetPreviousBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_GetPreviousBuffer(FW_HTextReader self, Environment* ev)
- {
- // No FW_SOM_TRY necessary
- ClassInvariants(self);
- if (self->fBufferSum == 0)
- {
- self->fNext = self->fStart;
- }
- else if (self->fBufferSum == self->fByteLength)
- {
- FW_PRIV_ASSERT(self->fLimit == self->fNext);
- self->fBufferSum -= BytesInBlock(self->fLimit, self->fStart);
- }
- else
- {
- FW_PRIV_ASSERT(self->fStart == self->fNext);
- DelegateGetPreviousBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- FW_PRIV_ASSERT(self->fStart < self->fLimit);
- self->fBufferSum -= BytesInBlock(self->fLimit, self->fStart);
- FW_PRIV_ASSERT(self->fBufferSum >= 0);
- self->fNext = self->fLimit;
- }
- // Invariants won't hold here
- // The calling function must modify fNext appropriately
- // Note that GetPreviousBuffer is a protected method,
- // so clients are not held responsible to restore invariants.
- // Also, subclasses shouldn't need to call this function directly.
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_SetPosition
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_SetPosition(FW_HTextReader self, Environment* ev, FW_ByteCount position)
- {
- // No FW_SOM_TRY necessary
- ClassInvariants(self);
- FW_PRIV_ASSERT(position>=0);
- FW_PRIV_ASSERT(position<=self->fByteLength);
- FW_ByteCount curPosition = FW_PrivTextReader_GetPosition(self);
- if (position < curPosition)
- FW_PrivTextReader_Backup(self, ev, curPosition-position);
- else if (position > curPosition)
- FW_PrivTextReader_Advance(self, ev, position-curPosition);
- ClassInvariants(self);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_GetByteLength
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_PrivTextReader_GetByteLength(FW_HTextReader self)
- {
- // No FW_SOM_TRY necessary
- return self->fByteLength;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_GetLocale
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_GetLocale(FW_HTextReader self, FW_Locale* locale)
- {
- // No FW_SOM_TRY necessary
- *locale = self->fLocale;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_PeekRunAhead
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_PeekRunAhead(FW_HTextReader self, const char** start, FW_ByteCount* length)
- {
- // No FW_SOM_TRY necessary, no error possible
- *start = self->fNext;
- *length = self->fLimit - self->fNext;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_PeekRunBehind
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextReader_PeekRunBehind(FW_HTextReader self, const char** end, FW_ByteCount* length)
- {
- // No FW_SOM_TRY necessary, no error possible
- *end = self->fNext;
- *length = self->fNext - self->fStart;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_PeekByte
- //----------------------------------------------------------------------------------------
-
- const char* FW_PrivTextReader_PeekByte(FW_HTextReader self)
- {
- // No FW_SOM_TRY necessary, no error possible
- ClassInvariants(self);
-
- if (self->fNext>=self->fStart && self->fNext<self->fLimit)
- return self->fNext;
- else
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextReader_PeekCharacterSize
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_PrivTextReader_PeekCharacterSize(FW_HTextReader self)
- {
- // No FW_SOM_TRY necessary, no error possible
- ClassInvariants(self);
-
- if (self->fNext >= self->fStart && self->fNext < self->fLimit)
- {
- if (FW_LocaleIsSingleByte(self->fLocale))
- return 1;
-
- // Check for double-byte character
- if (FW_CharIsDoubleByte(self->fNext, 0, self->fLocale))
- return 2;
-
- return 1;
- }
-
- return 0;
- }
-
- //========================================================================================
- // FW_SPrivTextWriter Functions
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // TextWriter_Initialize
- //----------------------------------------------------------------------------------------
-
- static void TextWriter_Initialize(FW_HTextWriter self, Environment* ev, FW_OTextRunWriter* adoptedWriter)
- {
- FW_SOM_TRY
- {
- FW_ByteCount length;
- FW_Locale locale;
- char* start = adoptedWriter->GetCurrentRun(ev, &length); // may throw
- self->fWriter = adoptedWriter;
- adoptedWriter->GetLocale(ev, &locale); // may throw
- self->fLocale = locale;
- self->fStart = start;
- self->fLimit = start + length;
- self->fNext = start;
- }
- FW_SOM_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPrivTextWriter_New
- //----------------------------------------------------------------------------------------
-
- FW_HTextWriter FW_PrivTextWriter_New(Environment* ev, FW_OTextRunWriter* adoptedWriter)
- {
- FW_SOM_TRY
- {
- FW_HTextWriter self = new FW_SPrivTextWriter; // may throw
- self->fWriter = 0;
- self->fStart = 0;
- self->fLimit = 0;
- self->fNext = 0;
- self->fBufferSum = 0;
- // self->fLocale.fScriptCode = 0;
- // self->fLocale.fLangCode = 0;
- self->fLocale = FW_PrivGetDefaultLocale();
- self->fRefCount = 0;
- TextWriter_Initialize(self, ev, adoptedWriter);
- return self;
- }
- FW_SOM_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TextWriter_Delete
- //----------------------------------------------------------------------------------------
-
- static void TextWriter_Delete(FW_HTextWriter self, Environment* ev)
- {
- // No FW_SOM_TRY necessary
- FW_PRIV_ASSERT(self->fNext <= self->fLimit);
- if (self->fStart < self->fNext)
- {
- FW_PrivTextWriter_FlushBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- }
- FW_PRIV_ASSERT(self->fStart == self->fNext);
- delete self;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_Acquire
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_Acquire(FW_HTextWriter self)
- {
- // No FW_SOM_TRY necessary, no error possible
- ++self->fRefCount;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_Release
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_Release(FW_HTextWriter self, Environment* ev)
- {
- // No FW_SOM_TRY necessary
- if (--self->fRefCount == 0)
- TextWriter_Delete(self, ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_SetBufferSum
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_SetBufferSum(FW_HTextWriter self, FW_ByteCount bufferSum)
- {
- // No FW_SOM_TRY necessary, no error possible
- self->fBufferSum = bufferSum;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_FlushBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_FlushBuffer(FW_HTextWriter self, Environment* ev)
- {
- FW_SOM_TRY
- {
- FW_PRIV_ASSERT(self->fNext <= self->fLimit);
- FW_ByteCount bytesToFlush = self->fNext - self->fStart;
- self->fWriter->FlushRun(ev, self->fStart, bytesToFlush); // may throw
- self->fBufferSum += bytesToFlush;
- self->fStart = self->fNext; // Mark the bytes as being written
- }
- FW_SOM_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_FlushAndGetNextBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_FlushAndGetNextBuffer(FW_HTextWriter self, Environment* ev)
- {
- FW_SOM_TRY
- {
- FW_ByteCount length;
- FW_PrivTextWriter_FlushBuffer(self, ev); // flush entire buffer
- self->fWriter->FlushRun(ev, self->fStart, self->fNext - self->fStart); // may throw
- self->fWriter->NewRun(ev, &self->fLocale); // may throw
- self->fStart = self->fWriter->GetCurrentRun(ev, &length); // may throw
- self->fLimit = self->fStart + length;
- self->fNext = self->fStart;
- }
- FW_SOM_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_PutCharacterAndAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_PutCharacterAndAdvance(FW_HTextWriter self,
- Environment* ev,
- FW_LChar character,
- FW_ByteCount bytesInChar)
- {
- // No FW_SOM_TRY necessary
-
- const FW_LChar kLowByteMask = 0x00FF;
-
- if (self->fNext >= self->fLimit)
- {
- FW_PrivTextWriter_FlushAndGetNextBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- }
-
- if (bytesInChar == 0)
- {
- bytesInChar = 1;
- if (!FW_LocaleIsSingleByte(self->fLocale))
- { // probably a double-byte character; check for non-zero high byte
- register FW_LChar ch = character >> 8;
- if (ch != 0)
- bytesInChar = 2;
- }
- }
-
- if (bytesInChar == 1)
- *self->fNext = (FW_Char) character;
- else
- {
- *self->fNext = character >> 8;
- *(self->fNext+1) = character & kLowByteMask;
- }
-
- self->fNext += bytesInChar;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_GetPosition
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_PrivTextWriter_GetPosition(FW_HTextWriter self, Environment* ev)
- {
- FW_UNUSED(ev);
- // No FW_SOM_TRY necessary, no error possible
- return self->fBufferSum + (self->fNext - self->fStart);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_WritePeek
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_WritePeek(FW_HTextWriter self, Environment* ev, char** start, FW_ByteCount* length)
- {
- // No FW_SOM_TRY necessary
- FW_PRIV_ASSERT(self->fNext <= self->fLimit);
- if (self->fNext == self->fLimit)
- {
- FW_PrivTextWriter_FlushAndGetNextBuffer(self, ev);
- if (FW_GetEvError(ev))
- return;
- }
-
- *start = self->fNext;
- *length = self->fLimit - self->fNext;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivTextWriter_WritePeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_PrivTextWriter_WritePeekAdvance(FW_HTextWriter self, char* start, FW_ByteCount bytesWritten)
- {
- #ifndef FW_DEBUG
- FW_UNUSED(start);
- #endif
- // No FW_SOM_TRY necessary, no error possible
- FW_PRIV_ASSERT(start == self->fNext);
- FW_PRIV_ASSERT(bytesWritten <= self->fLimit - self->fNext);
- self->fNext += bytesWritten;
- }
-
-
-