* style cleanup - no functional change
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37984 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -18,22 +19,25 @@
|
|||||||
|
|
||||||
#include "TextGapBuffer.h"
|
#include "TextGapBuffer.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
static const int32 kTextGapBufferBlockSize = 2048;
|
static const int32 kTextGapBufferBlockSize = 2048;
|
||||||
|
|
||||||
|
|
||||||
TextGapBuffer::TextGapBuffer()
|
TextGapBuffer::TextGapBuffer()
|
||||||
: fItemCount(0),
|
:
|
||||||
fBuffer(NULL),
|
fItemCount(0),
|
||||||
fBufferCount(kTextGapBufferBlockSize + fItemCount),
|
fBuffer(NULL),
|
||||||
fGapIndex(fItemCount),
|
fBufferCount(kTextGapBufferBlockSize + fItemCount),
|
||||||
fGapCount(fBufferCount - fGapIndex),
|
fGapIndex(fItemCount),
|
||||||
fScratchBuffer(NULL),
|
fGapCount(fBufferCount - fGapIndex),
|
||||||
fScratchSize(0),
|
fScratchBuffer(NULL),
|
||||||
fPasswordMode(false)
|
fScratchSize(0),
|
||||||
|
fPasswordMode(false)
|
||||||
{
|
{
|
||||||
fBuffer = (char *)malloc(kTextGapBufferBlockSize + fItemCount);
|
fBuffer = (char*)malloc(kTextGapBufferBlockSize + fItemCount);
|
||||||
fScratchBuffer = NULL;
|
fScratchBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +50,7 @@ TextGapBuffer::~TextGapBuffer()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextGapBuffer::InsertText(const char *inText, int32 inNumItems, int32 inAtIndex)
|
TextGapBuffer::InsertText(const char* inText, int32 inNumItems, int32 inAtIndex)
|
||||||
{
|
{
|
||||||
if (inNumItems < 1)
|
if (inNumItems < 1)
|
||||||
return;
|
return;
|
||||||
@@ -69,7 +73,8 @@ TextGapBuffer::InsertText(const char *inText, int32 inNumItems, int32 inAtIndex)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextGapBuffer::InsertText(BFile *file, int32 fileOffset, int32 inNumItems, int32 inAtIndex)
|
TextGapBuffer::InsertText(BFile* file, int32 fileOffset, int32 inNumItems,
|
||||||
|
int32 inAtIndex)
|
||||||
{
|
{
|
||||||
off_t fileSize;
|
off_t fileSize;
|
||||||
|
|
||||||
@@ -162,7 +167,7 @@ TextGapBuffer::SizeGapTo(long inCount)
|
|||||||
if (inCount == fGapCount)
|
if (inCount == fGapCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fBuffer = (char *)realloc(fBuffer, fItemCount + inCount);
|
fBuffer = (char*)realloc(fBuffer, fItemCount + inCount);
|
||||||
memmove(fBuffer + fGapIndex + inCount,
|
memmove(fBuffer + fGapIndex + inCount,
|
||||||
fBuffer + fGapIndex + fGapCount,
|
fBuffer + fGapIndex + fGapCount,
|
||||||
fBufferCount - (fGapIndex + fGapCount));
|
fBufferCount - (fGapIndex + fGapCount));
|
||||||
@@ -172,10 +177,10 @@ TextGapBuffer::SizeGapTo(long inCount)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
const char*
|
||||||
TextGapBuffer::GetString(int32 fromOffset, int32 *_numBytes)
|
TextGapBuffer::GetString(int32 fromOffset, int32* _numBytes)
|
||||||
{
|
{
|
||||||
const char *result = "";
|
const char* result = "";
|
||||||
if (_numBytes == NULL)
|
if (_numBytes == NULL)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@@ -193,7 +198,7 @@ TextGapBuffer::GetString(int32 fromOffset, int32 *_numBytes)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (fScratchSize < numBytes) {
|
if (fScratchSize < numBytes) {
|
||||||
fScratchBuffer = (char *)realloc(fScratchBuffer, numBytes);
|
fScratchBuffer = (char*)realloc(fScratchBuffer, numBytes);
|
||||||
fScratchSize = numBytes;
|
fScratchSize = numBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,20 +208,20 @@ TextGapBuffer::GetString(int32 fromOffset, int32 *_numBytes)
|
|||||||
result = fScratchBuffer;
|
result = fScratchBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this could be improved. We are overwriting what we did some lines ago,
|
// TODO: this could be improved. We are overwriting what we did some lines
|
||||||
// we could just avoid to do that.
|
// ago, we could just avoid to do that.
|
||||||
if (fPasswordMode) {
|
if (fPasswordMode) {
|
||||||
uint32 numChars = UTF8CountChars(result, numBytes);
|
uint32 numChars = UTF8CountChars(result, numBytes);
|
||||||
uint32 charLen = UTF8CountBytes(B_UTF8_BULLET, 1);
|
uint32 charLen = UTF8CountBytes(B_UTF8_BULLET, 1);
|
||||||
uint32 newSize = numChars * charLen;
|
uint32 newSize = numChars * charLen;
|
||||||
|
|
||||||
if ((uint32)fScratchSize < newSize) {
|
if ((uint32)fScratchSize < newSize) {
|
||||||
fScratchBuffer = (char *)realloc(fScratchBuffer, newSize);
|
fScratchBuffer = (char*)realloc(fScratchBuffer, newSize);
|
||||||
fScratchSize = newSize;
|
fScratchSize = newSize;
|
||||||
}
|
}
|
||||||
result = fScratchBuffer;
|
result = fScratchBuffer;
|
||||||
|
|
||||||
char *scratchPtr = fScratchBuffer;
|
char* scratchPtr = fScratchBuffer;
|
||||||
for (uint32 i = 0; i < numChars; i++) {
|
for (uint32 i = 0; i < numChars; i++) {
|
||||||
memcpy(scratchPtr, B_UTF8_BULLET, charLen);
|
memcpy(scratchPtr, B_UTF8_BULLET, charLen);
|
||||||
scratchPtr += charLen;
|
scratchPtr += charLen;
|
||||||
@@ -230,7 +235,7 @@ TextGapBuffer::GetString(int32 fromOffset, int32 *_numBytes)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TextGapBuffer::FindChar(char inChar, long fromIndex, long *ioDelta)
|
TextGapBuffer::FindChar(char inChar, long fromIndex, long* ioDelta)
|
||||||
{
|
{
|
||||||
long numChars = *ioDelta;
|
long numChars = *ioDelta;
|
||||||
for (long i = 0; i < numChars; i++) {
|
for (long i = 0; i < numChars; i++) {
|
||||||
@@ -247,10 +252,10 @@ TextGapBuffer::FindChar(char inChar, long fromIndex, long *ioDelta)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
const char*
|
||||||
TextGapBuffer::Text()
|
TextGapBuffer::Text()
|
||||||
{
|
{
|
||||||
const char *realText = RealText();
|
const char* realText = RealText();
|
||||||
|
|
||||||
if (fPasswordMode) {
|
if (fPasswordMode) {
|
||||||
const uint32 numChars = UTF8CountChars(realText, Length());
|
const uint32 numChars = UTF8CountChars(realText, Length());
|
||||||
@@ -258,11 +263,11 @@ TextGapBuffer::Text()
|
|||||||
uint32 newSize = numChars * bulletCharLen + 1;
|
uint32 newSize = numChars * bulletCharLen + 1;
|
||||||
|
|
||||||
if ((uint32)fScratchSize < newSize) {
|
if ((uint32)fScratchSize < newSize) {
|
||||||
fScratchBuffer = (char *)realloc(fScratchBuffer, newSize);
|
fScratchBuffer = (char*)realloc(fScratchBuffer, newSize);
|
||||||
fScratchSize = newSize;
|
fScratchSize = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *scratchPtr = fScratchBuffer;
|
char* scratchPtr = fScratchBuffer;
|
||||||
for (uint32 i = 0; i < numChars; i++) {
|
for (uint32 i = 0; i < numChars; i++) {
|
||||||
memcpy(scratchPtr, B_UTF8_BULLET, bulletCharLen);
|
memcpy(scratchPtr, B_UTF8_BULLET, bulletCharLen);
|
||||||
scratchPtr += bulletCharLen;
|
scratchPtr += bulletCharLen;
|
||||||
@@ -276,7 +281,7 @@ TextGapBuffer::Text()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
const char*
|
||||||
TextGapBuffer::RealText()
|
TextGapBuffer::RealText()
|
||||||
{
|
{
|
||||||
MoveGapTo(fItemCount);
|
MoveGapTo(fItemCount);
|
||||||
@@ -290,7 +295,7 @@ TextGapBuffer::RealText()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextGapBuffer::GetString(int32 offset, int32 length, char *buffer)
|
TextGapBuffer::GetString(int32 offset, int32 length, char* buffer)
|
||||||
{
|
{
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return;
|
return;
|
||||||
@@ -308,7 +313,7 @@ TextGapBuffer::GetString(int32 offset, int32 length, char *buffer)
|
|||||||
bool isEndBeforeGap = ((offset + length - 1) < fGapIndex);
|
bool isEndBeforeGap = ((offset + length - 1) < fGapIndex);
|
||||||
|
|
||||||
if (isStartBeforeGap == isEndBeforeGap) {
|
if (isStartBeforeGap == isEndBeforeGap) {
|
||||||
char *source = fBuffer + offset;
|
char* source = fBuffer + offset;
|
||||||
if (!isStartBeforeGap)
|
if (!isStartBeforeGap)
|
||||||
source += fGapCount;
|
source += fGapCount;
|
||||||
|
|
||||||
|
|||||||
@@ -5,57 +5,59 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Marc Flerackers ([email protected])
|
* Marc Flerackers ([email protected])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TEXTGAPBUFFER_H
|
#ifndef __TEXTGAPBUFFER_H
|
||||||
#define __TEXTGAPBUFFER_H
|
#define __TEXTGAPBUFFER_H
|
||||||
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
|
|
||||||
class BFile;
|
class BFile;
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
class TextGapBuffer {
|
class TextGapBuffer {
|
||||||
public:
|
public:
|
||||||
TextGapBuffer();
|
TextGapBuffer();
|
||||||
virtual ~TextGapBuffer();
|
~TextGapBuffer();
|
||||||
|
|
||||||
void InsertText(const char *inText, int32 inNumItems,
|
void InsertText(const char* inText, int32 inNumItems,
|
||||||
int32 inAtIndex);
|
int32 inAtIndex);
|
||||||
void InsertText(BFile *file, int32 fileOffset, int32 amount,
|
void InsertText(BFile* file, int32 fileOffset,
|
||||||
int32 atIndex);
|
int32 amount, int32 atIndex);
|
||||||
void RemoveRange(int32 start, int32 end);
|
void RemoveRange(int32 start, int32 end);
|
||||||
|
|
||||||
void MoveGapTo(int32 toIndex);
|
void MoveGapTo(int32 toIndex);
|
||||||
void SizeGapTo(int32 inCount);
|
void SizeGapTo(int32 inCount);
|
||||||
|
|
||||||
bool FindChar(char inChar, int32 fromIndex, int32 *ioDelta);
|
bool FindChar(char inChar, int32 fromIndex,
|
||||||
|
int32* ioDelta);
|
||||||
|
|
||||||
const char *Text();
|
const char* Text();
|
||||||
const char *RealText();
|
const char* RealText();
|
||||||
int32 Length() const;
|
int32 Length() const;
|
||||||
|
|
||||||
const char *GetString(int32 fromOffset, int32 *numBytes);
|
const char* GetString(int32 fromOffset, int32* numBytes);
|
||||||
void GetString(int32 offset, int32 length, char *buffer);
|
void GetString(int32 offset, int32 length,
|
||||||
|
char* buffer);
|
||||||
|
|
||||||
char RealCharAt(int32 offset) const;
|
char RealCharAt(int32 offset) const;
|
||||||
|
|
||||||
bool PasswordMode() const;
|
bool PasswordMode() const;
|
||||||
void SetPasswordMode(bool);
|
void SetPasswordMode(bool);
|
||||||
|
|
||||||
// void Resize(int32 size);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32 fItemCount; // logical count
|
int32 fItemCount; // logical count
|
||||||
char * fBuffer; // allocated memory
|
char* fBuffer; // allocated memory
|
||||||
int32 fBufferCount; // physical count
|
int32 fBufferCount; // physical count
|
||||||
int32 fGapIndex; // gap position
|
int32 fGapIndex; // gap position
|
||||||
int32 fGapCount; // gap count
|
int32 fGapCount; // gap count
|
||||||
char * fScratchBuffer; // for GetString
|
char* fScratchBuffer; // for GetString
|
||||||
int32 fScratchSize; // scratch size
|
int32 fScratchSize; // scratch size
|
||||||
bool fPasswordMode;
|
bool fPasswordMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +80,8 @@ TextGapBuffer::RealCharAt(int32 index) const
|
|||||||
return index < fGapIndex ? fBuffer[index] : fBuffer[index + fGapCount];
|
return index < fGapIndex ? fBuffer[index] : fBuffer[index + fGapCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|
||||||
#endif //__TEXTGAPBUFFER_H
|
#endif //__TEXTGAPBUFFER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user