2017-01-23 06:19:43 +00:00
|
|
|
/*
|
|
|
|
* Helpers for doing long range seeks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
#if !defined(FCODER_LONG_SEEK_H)
|
|
|
|
#define FCODER_LONG_SEEK_H
|
|
|
|
|
|
|
|
#include "4coder_helper/4coder_streaming.h"
|
|
|
|
#include "4coder_lib/4coder_mem.h"
|
2017-11-21 00:35:35 +00:00
|
|
|
#include "4coder_lib/4cpp_lexer.h"
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Whitespace Based Seeks
|
|
|
|
//
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
seek_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char chunk[1024];
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t chunk_size = sizeof(chunk);
|
2017-01-23 06:19:43 +00:00
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t still_looping;
|
|
|
|
char at_pos;
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
2017-03-23 19:15:33 +00:00
|
|
|
still_looping = 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
|
|
|
at_pos = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
if (at_pos == '\n'){
|
|
|
|
goto double_break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break:;
|
|
|
|
|
|
|
|
if (pos > buffer->size){
|
|
|
|
pos = buffer->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char chunk[1024];
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t chunk_size = sizeof(chunk);
|
2017-01-23 06:19:43 +00:00
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t still_looping;
|
|
|
|
char at_pos;
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
--pos;
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
2017-03-23 19:15:33 +00:00
|
|
|
still_looping = 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
|
|
|
at_pos = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
if (at_pos == '\n'){
|
|
|
|
goto double_break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break:;
|
|
|
|
|
|
|
|
if (pos != 0){
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
if (pos < 0){
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Summary *buffer){
|
|
|
|
refresh_view(app, view);
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos);
|
2017-01-23 06:19:43 +00:00
|
|
|
char space[1024];
|
|
|
|
Stream_Chunk chunk = {0};
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t still_looping = false;
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t i = new_pos;
|
2017-01-23 06:19:43 +00:00
|
|
|
if (init_stream_chunk(&chunk, app, buffer, i, space, sizeof(space))){
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; i < chunk.end; ++i){
|
2017-01-23 06:19:43 +00:00
|
|
|
char at_pos = chunk.data[i];
|
|
|
|
if (at_pos == '\n' || !char_is_whitespace(at_pos)){
|
|
|
|
goto break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&chunk);
|
|
|
|
}while(still_looping);
|
|
|
|
break2:;
|
|
|
|
|
|
|
|
if (i > view->cursor.pos){
|
|
|
|
view_set_cursor(app, view, seek_pos(i), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char chunk[1024];
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t chunk_size = sizeof(chunk);
|
2017-01-23 06:19:43 +00:00
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
char at_pos;
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
--pos;
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
|
|
|
// Step 1: Find the first non-whitespace character
|
|
|
|
// behind the current position.
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t still_looping = 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
while (still_looping){
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
|
|
|
at_pos = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
if (!char_is_whitespace(at_pos)){
|
|
|
|
goto double_break_1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}
|
|
|
|
double_break_1:;
|
|
|
|
|
|
|
|
// Step 2: Continue scanning backward, at each '\n'
|
|
|
|
// mark the beginning of another line by setting
|
|
|
|
// no_hard to true, set it back to false if a
|
|
|
|
// non-whitespace character is discovered before
|
|
|
|
// the next '\n'
|
|
|
|
int32_t no_hard = false;
|
|
|
|
while (still_looping){
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
|
|
|
at_pos = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
if (at_pos == '\n'){
|
|
|
|
if (no_hard){
|
|
|
|
goto double_break_2;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
no_hard = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!char_is_whitespace(at_pos)){
|
|
|
|
no_hard = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}
|
|
|
|
double_break_2:;
|
|
|
|
|
|
|
|
if (pos != 0){
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char chunk[1024];
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t chunk_size = sizeof(chunk);
|
2017-01-23 06:19:43 +00:00
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
|
|
|
// step 1: find the first non-whitespace character
|
|
|
|
// ahead of the current position.
|
2017-03-29 16:32:06 +00:00
|
|
|
bool32 still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-03-29 16:32:06 +00:00
|
|
|
char at_pos = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
if (!char_is_whitespace(at_pos)){
|
|
|
|
goto double_break_1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
} while(still_looping);
|
|
|
|
double_break_1:;
|
|
|
|
|
|
|
|
// step 2: continue scanning forward, at each '\n'
|
|
|
|
// mark it as the beginning of a new line by updating
|
|
|
|
// the prev_endline value. if another '\n' is found
|
|
|
|
// with non-whitespace then the previous line was
|
|
|
|
// all whitespace.
|
2017-03-29 16:32:06 +00:00
|
|
|
bool32 no_hard = false;
|
|
|
|
int32_t prev_endline = -1;
|
2017-01-23 06:19:43 +00:00
|
|
|
while(still_looping){
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-03-29 16:32:06 +00:00
|
|
|
char at_pos = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
if (at_pos == '\n'){
|
|
|
|
if (no_hard){
|
|
|
|
goto double_break_2;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
no_hard = true;
|
|
|
|
prev_endline = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!char_is_whitespace(at_pos)){
|
|
|
|
no_hard = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}
|
|
|
|
double_break_2:;
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
if (prev_endline == -1 || prev_endline+1 >= buffer->size){
|
2017-01-23 06:19:43 +00:00
|
|
|
pos = buffer->size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos = prev_endline+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
bool32 still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (!char_is_whitespace(stream.data[pos])){
|
|
|
|
goto double_break1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (char_is_whitespace(stream.data[pos])){
|
|
|
|
goto double_break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break2:;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
--pos;
|
|
|
|
if (pos > 0){
|
|
|
|
if (init_stream_chunk(&stream, app, buffer,
|
|
|
|
pos, data_chunk, sizeof(data_chunk))){
|
|
|
|
|
|
|
|
bool32 still_looping = 1;
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (!char_is_whitespace(stream.data[pos])){
|
|
|
|
goto double_break1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
|
|
|
|
still_looping = 1;
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (char_is_whitespace(stream.data[pos])){
|
|
|
|
++pos;
|
|
|
|
goto double_break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break2:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Boundary Type Seeks
|
|
|
|
//
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
bool32 still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-03-27 22:36:42 +00:00
|
|
|
if (char_is_alpha_numeric_true_utf8(stream.data[pos])){
|
2017-01-23 06:19:43 +00:00
|
|
|
goto double_break1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-03-27 22:36:42 +00:00
|
|
|
if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){
|
2017-01-23 06:19:43 +00:00
|
|
|
goto double_break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break2:;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
--pos;
|
|
|
|
if (pos > 0){
|
2017-03-27 22:36:42 +00:00
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
2017-03-29 16:32:06 +00:00
|
|
|
bool32 still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
2017-03-27 22:36:42 +00:00
|
|
|
if (char_is_alpha_numeric_true_utf8(stream.data[pos])){
|
2017-01-23 06:19:43 +00:00
|
|
|
goto double_break1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
still_looping = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
2017-03-27 22:36:42 +00:00
|
|
|
if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){
|
2017-01-23 06:19:43 +00:00
|
|
|
++pos;
|
|
|
|
goto double_break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break2:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
|
|
|
bool32 still_looping = true;
|
|
|
|
do{
|
|
|
|
for (; pos < stream.end; ++pos){
|
|
|
|
if (char_is_alpha_numeric_utf8(stream.data[pos])){
|
|
|
|
goto double_break1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
|
|
|
|
still_looping = true;
|
|
|
|
do{
|
|
|
|
for (; pos < stream.end; ++pos){
|
|
|
|
if (!char_is_alpha_numeric_utf8(stream.data[pos])){
|
|
|
|
goto double_break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break2:;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
|
|
|
buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
--pos;
|
|
|
|
if (pos > 0){
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
|
|
|
|
|
|
|
bool32 still_looping = true;
|
|
|
|
do{
|
|
|
|
for (; pos >= stream.start; --pos){
|
|
|
|
if (char_is_alpha_numeric_utf8(stream.data[pos])){
|
|
|
|
goto double_break1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
|
|
|
|
still_looping = true;
|
|
|
|
do{
|
|
|
|
for (; pos >= stream.start; --pos){
|
|
|
|
if (!char_is_alpha_numeric_utf8(stream.data[pos])){
|
|
|
|
++pos;
|
|
|
|
goto double_break2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break2:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
++pos;
|
|
|
|
if (pos < an_pos){
|
|
|
|
stream.max_end = an_pos;
|
2017-03-27 22:36:42 +00:00
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-30 15:18:16 +00:00
|
|
|
uint8_t c = 0, pc = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
++pos;
|
|
|
|
|
2017-03-30 15:18:16 +00:00
|
|
|
bool32 still_looping = false;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos < stream.end; ++pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
c = stream.data[pos];
|
2017-03-30 15:18:16 +00:00
|
|
|
if (char_is_upper(c) && char_is_lower_utf8(pc)){
|
2017-01-23 06:19:43 +00:00
|
|
|
goto double_break1;
|
|
|
|
}
|
2017-03-30 15:18:16 +00:00
|
|
|
pc = c;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos = an_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char data_chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
--pos;
|
|
|
|
if (pos > 0){
|
|
|
|
stream.min_start = an_pos+1;
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
|
|
|
|
|
2017-03-30 15:18:16 +00:00
|
|
|
char c = 0, pc = stream.data[pos];
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-30 15:18:16 +00:00
|
|
|
bool32 still_looping = false;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (; pos >= stream.start; --pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
c = stream.data[pos];
|
2017-03-30 15:18:16 +00:00
|
|
|
if (char_is_upper(c) && char_is_lower_utf8(pc)){
|
2017-01-23 06:19:43 +00:00
|
|
|
goto double_break1;
|
|
|
|
}
|
2017-03-30 15:18:16 +00:00
|
|
|
pc = c;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
double_break1:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pos);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
|
|
|
int32_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos);
|
|
|
|
int32_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos);
|
2017-01-23 06:19:43 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
|
|
|
int32_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos);
|
|
|
|
int32_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos);
|
2017-01-23 06:19:43 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
2017-03-23 19:16:39 +00:00
|
|
|
seek_token_left(Cpp_Token_Array *tokens, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos);
|
|
|
|
if (get.token_index == -1){
|
|
|
|
get.token_index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cpp_Token *token = tokens->tokens + get.token_index;
|
|
|
|
if (token->start == pos && get.token_index > 0){
|
|
|
|
--token;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(token->start);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
2017-03-23 19:16:39 +00:00
|
|
|
seek_token_right(Cpp_Token_Array *tokens, int32_t pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos);
|
|
|
|
if (get.in_whitespace){
|
|
|
|
++get.token_index;
|
|
|
|
}
|
2017-03-23 19:16:39 +00:00
|
|
|
if (get.token_index >= tokens->count){
|
|
|
|
get.token_index = tokens->count-1;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 19:16:39 +00:00
|
|
|
Cpp_Token *token = tokens->tokens + get.token_index;
|
2017-01-23 06:19:43 +00:00
|
|
|
return(token->start + token->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cpp_Token_Array
|
|
|
|
buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){
|
|
|
|
Cpp_Token_Array array = {0};
|
|
|
|
|
|
|
|
if (buffer->exists && buffer->is_lexed){
|
|
|
|
array.count = buffer_token_count(app, buffer);
|
|
|
|
array.max_count = array.count;
|
|
|
|
array.tokens = push_array(part, Cpp_Token, array.count);
|
|
|
|
buffer_read_tokens(app, buffer, 0, array.count, array.tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(array);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/*
|
2017-01-23 06:19:43 +00:00
|
|
|
DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.)
|
|
|
|
DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.)
|
|
|
|
DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.)
|
|
|
|
DOC_PARAM(flags, This field specifies the types of boundaries at which the seek should stop.)
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
DOC_RETURN(This call returns the absolute position where the seek stopped.
|
|
|
|
If the seek goes below 0 the returned value is -1.
|
|
|
|
If the seek goes past the end the returned value is the size of the buffer.)
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
DOC_SEE(Seek_Boundary_Flag)
|
|
|
|
DOC_SEE(4coder_Buffer_Positioning_System)
|
|
|
|
*/{
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t result = 0;
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
// TODO(allen): reduce duplication?
|
|
|
|
Temp_Memory temp = begin_temp_memory(part);
|
|
|
|
if (buffer->exists){
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t pos[4];
|
|
|
|
int32_t size = buffer->size;
|
|
|
|
int32_t new_pos = 0;
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
if (start_pos < 0){
|
|
|
|
start_pos = 0;
|
|
|
|
}
|
|
|
|
else if (start_pos > size){
|
|
|
|
start_pos = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seek_forward){
|
|
|
|
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
|
|
|
pos[i] = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BoundaryWhitespace){
|
|
|
|
pos[0] = buffer_seek_whitespace_right(app, buffer, start_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BoundaryToken){
|
|
|
|
if (buffer->tokens_are_ready){
|
|
|
|
Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer);
|
|
|
|
pos[1] = seek_token_right(&array, start_pos);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos[1] = buffer_seek_whitespace_right(app, buffer, start_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BoundaryAlphanumeric){
|
|
|
|
pos[2] = buffer_seek_alphanumeric_right(app, buffer, start_pos);
|
|
|
|
if (flags & BoundaryCamelCase){
|
|
|
|
pos[3] = buffer_seek_range_camel_right(app, buffer, start_pos, pos[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (flags & BoundaryCamelCase){
|
|
|
|
pos[3] = buffer_seek_alphanumeric_or_camel_right(app, buffer, start_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_pos = size;
|
|
|
|
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
|
|
|
if (pos[i] < new_pos){
|
|
|
|
new_pos = pos[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
|
|
|
pos[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BoundaryWhitespace){
|
|
|
|
pos[0] = buffer_seek_whitespace_left(app, buffer, start_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BoundaryToken){
|
|
|
|
if (buffer->tokens_are_ready){
|
|
|
|
Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer);
|
|
|
|
pos[1] = seek_token_left(&array, start_pos);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
pos[1] = buffer_seek_whitespace_left(app, buffer, start_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BoundaryAlphanumeric){
|
|
|
|
pos[2] = buffer_seek_alphanumeric_left(app, buffer, start_pos);
|
|
|
|
if (flags & BoundaryCamelCase){
|
|
|
|
pos[3] = buffer_seek_range_camel_left(app, buffer, start_pos, pos[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (flags & BoundaryCamelCase){
|
|
|
|
pos[3] = buffer_seek_alphanumeric_or_camel_left(app, buffer, start_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_pos = 0;
|
|
|
|
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
|
|
|
if (pos[i] > new_pos){
|
|
|
|
new_pos = pos[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = new_pos;
|
|
|
|
}
|
|
|
|
end_temp_memory(temp);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Character Seeks
|
|
|
|
//
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
void
|
|
|
|
buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (buffer->exists){
|
|
|
|
char chunk[1024];
|
|
|
|
int32_t size = sizeof(chunk);
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){
|
|
|
|
int32_t still_looping = 1;
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for(; pos < stream.end; ++pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char at_pos = stream.data[pos];
|
|
|
|
if (at_pos == delim){
|
|
|
|
*result = pos;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while (still_looping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = buffer->size;
|
|
|
|
|
|
|
|
finished:;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (buffer->exists){
|
|
|
|
char chunk[1024];
|
|
|
|
int32_t size = sizeof(chunk);
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){
|
|
|
|
int32_t still_looping = 1;
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for(; pos >= stream.start; --pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char at_pos = stream.data[pos];
|
|
|
|
if (at_pos == delim){
|
|
|
|
*result = pos;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while (still_looping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
finished:;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Buffer Substring Seeks
|
|
|
|
//
|
|
|
|
|
|
|
|
// TODO(allen): This duplication is driving me crazy... I've gotta
|
|
|
|
// upgrade the meta programming system another level.
|
|
|
|
|
|
|
|
// NOTE(allen): This is limitted to a string size of 512.
|
|
|
|
// You can push it up or do something more clever by just
|
|
|
|
// replacing char read_buffer[512]; with more memory.
|
|
|
|
static void
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){
|
2017-01-23 06:19:43 +00:00
|
|
|
char read_buffer[512];
|
|
|
|
|
|
|
|
if (buffer->size > end){
|
|
|
|
*result = buffer->size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*result = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > 0 && size <= sizeof(read_buffer)){
|
|
|
|
if (buffer->exists){
|
|
|
|
String read_str = make_fixed_width_string(read_buffer);
|
2017-03-23 19:15:33 +00:00
|
|
|
String needle_str = make_string(str, size);
|
2017-01-23 06:19:43 +00:00
|
|
|
char first_char = str[0];
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
read_str.size = size;
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
char chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
stream.max_end = end;
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t still_looping = 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for(; pos < stream.end; ++pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char at_pos = stream.data[pos];
|
|
|
|
if (at_pos == first_char){
|
|
|
|
buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
|
|
|
if (match_ss(needle_str, read_str)){
|
|
|
|
*result = pos;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while (still_looping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end == 0){
|
|
|
|
*result = buffer->size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*result = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
finished:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): This is limitted to a string size of 512.
|
|
|
|
// You can push it up or do something more clever by just
|
|
|
|
// replacing char read_buffer[512]; with more memory.
|
|
|
|
static void
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){
|
2017-01-23 06:19:43 +00:00
|
|
|
char read_buffer[512];
|
|
|
|
|
|
|
|
*result = min-1;
|
|
|
|
if (size > 0 && size <= sizeof(read_buffer)){
|
|
|
|
if (buffer->exists){
|
|
|
|
String read_str = make_fixed_width_string(read_buffer);
|
2017-03-23 19:15:33 +00:00
|
|
|
String needle_str = make_string(str, size);
|
2017-01-23 06:19:43 +00:00
|
|
|
char first_char = str[0];
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
read_str.size = size;
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
char chunk[1024];
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
stream.min_start = min;
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){
|
|
|
|
int32_t still_looping = 1;
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for(; pos >= stream.start; --pos){
|
2017-01-23 06:19:43 +00:00
|
|
|
char at_pos = stream.data[pos];
|
|
|
|
if (at_pos == first_char){
|
|
|
|
buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
|
|
|
if (match_ss(needle_str, read_str)){
|
|
|
|
*result = pos;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while (still_looping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finished:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): This is limitted to a string size of 512.
|
|
|
|
// You can push it up or do something more clever by just
|
|
|
|
// replacing char read_buffer[512]; with more memory.
|
|
|
|
static void
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){
|
2017-01-23 06:19:43 +00:00
|
|
|
char read_buffer[512];
|
|
|
|
char chunk[1024];
|
|
|
|
int32_t chunk_size = sizeof(chunk);
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
stream.max_end = end;
|
|
|
|
|
|
|
|
if (buffer->size > end){
|
|
|
|
*result = buffer->size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*result = end;
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
if (size > 0 && size <= sizeof(read_buffer)){
|
|
|
|
if (buffer->exists){
|
|
|
|
String read_str = make_fixed_width_string(read_buffer);
|
|
|
|
String needle_str = make_string(str, size);
|
|
|
|
char first_char = char_to_upper(str[0]);
|
|
|
|
|
|
|
|
read_str.size = size;
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
|
|
|
int32_t still_looping = 1;
|
|
|
|
do{
|
|
|
|
for(; pos < stream.end; ++pos){
|
|
|
|
char at_pos = char_to_upper(stream.data[pos]);
|
|
|
|
if (at_pos == first_char){
|
|
|
|
buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
|
|
|
if (match_insensitive_ss(needle_str, read_str)){
|
|
|
|
*result = pos;
|
|
|
|
goto finished;
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-23 19:15:33 +00:00
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while (still_looping);
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
2017-03-23 19:15:33 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
finished:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): This is limitted to a string size of 512.
|
|
|
|
// You can push it up or do something more clever by just
|
|
|
|
// replacing char read_buffer[512]; with more memory.
|
|
|
|
static void
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){
|
2017-01-23 06:19:43 +00:00
|
|
|
char read_buffer[512];
|
|
|
|
char chunk[1024];
|
|
|
|
int32_t chunk_size = sizeof(chunk);
|
|
|
|
Stream_Chunk stream = {0};
|
|
|
|
stream.min_start = min;
|
|
|
|
|
|
|
|
*result = min-1;
|
2017-03-23 19:15:33 +00:00
|
|
|
if (size > 0 && size <= sizeof(read_buffer)){
|
|
|
|
if (buffer->exists){
|
|
|
|
String read_str = make_fixed_width_string(read_buffer);
|
|
|
|
String needle_str = make_string(str, size);
|
|
|
|
char first_char = char_to_upper(str[0]);
|
|
|
|
|
|
|
|
read_str.size = size;
|
|
|
|
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
|
|
|
int32_t still_looping = 1;
|
|
|
|
do{
|
|
|
|
for(; pos >= stream.start; --pos){
|
|
|
|
char at_pos = char_to_upper(stream.data[pos]);
|
|
|
|
if (at_pos == first_char){
|
|
|
|
buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
|
|
|
if (match_insensitive_ss(needle_str, read_str)){
|
|
|
|
*result = pos;
|
|
|
|
goto finished;
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-23 19:15:33 +00:00
|
|
|
still_looping = backward_stream_chunk(&stream);
|
|
|
|
}while (still_looping);
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
2017-03-23 19:15:33 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
finished:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Buffer Line Positioning
|
|
|
|
//
|
|
|
|
|
2017-04-15 21:47:23 +00:00
|
|
|
static bool32
|
2017-03-23 19:15:33 +00:00
|
|
|
read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, String *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
Partial_Cursor begin = {0};
|
|
|
|
Partial_Cursor end = {0};
|
|
|
|
|
2017-04-15 21:47:23 +00:00
|
|
|
bool32 success = false;
|
2017-03-23 19:15:33 +00:00
|
|
|
|
|
|
|
if (buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &begin)){
|
|
|
|
if (buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &end)){
|
|
|
|
if (begin.line == line){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer->size){
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t size = (end.pos - begin.pos);
|
2017-11-13 17:34:31 +00:00
|
|
|
int32_t alloc_size = size + 1;
|
|
|
|
char *memory = push_array(part, char, alloc_size);
|
|
|
|
if (memory != 0){
|
|
|
|
*str = make_string(memory, 0, alloc_size);
|
2017-04-15 21:47:23 +00:00
|
|
|
success = true;
|
2017-01-23 06:19:43 +00:00
|
|
|
buffer_read_range(app, buffer, begin.pos, end.pos, str->str);
|
2017-03-23 19:15:33 +00:00
|
|
|
str->size = size;
|
2017-01-23 06:19:43 +00:00
|
|
|
terminate_with_null(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){
|
2017-01-23 06:19:43 +00:00
|
|
|
Partial_Cursor partial_cursor;
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t result = buffer->size;
|
2017-01-23 06:19:43 +00:00
|
|
|
if (line <= buffer->line_count){
|
|
|
|
buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor);
|
|
|
|
result = partial_cursor.pos;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
|
|
|
buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line){
|
2017-01-23 06:19:43 +00:00
|
|
|
Partial_Cursor partial_cursor;
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t result = buffer->size;
|
2017-01-23 06:19:43 +00:00
|
|
|
if (line <= buffer->line_count){
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &partial_cursor);
|
2017-01-23 06:19:43 +00:00
|
|
|
result = partial_cursor.pos;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool32
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t line){
|
2017-01-23 06:19:43 +00:00
|
|
|
Partial_Cursor start, end;
|
|
|
|
bool32 result = 0;
|
|
|
|
if (line <= buffer->line_count){
|
2017-03-23 19:15:33 +00:00
|
|
|
buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &start);
|
|
|
|
buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &end);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static const int32_t chunk_size = 1024;
|
2017-01-23 06:19:43 +00:00
|
|
|
char chunk[chunk_size];
|
|
|
|
Stream_Chunk stream = {0};
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t i = start.pos;
|
2017-01-23 06:19:43 +00:00
|
|
|
stream.max_end = end.pos;
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
if (init_stream_chunk(&stream, app, buffer, i, chunk, chunk_size)){
|
|
|
|
bool32 still_looping = false;
|
|
|
|
do{
|
2017-03-23 19:15:33 +00:00
|
|
|
for (;i < stream.end; ++i){
|
2017-01-23 06:19:43 +00:00
|
|
|
char c = stream.data[i];
|
|
|
|
if (!(c == ' ' || c == '\t' || c == '\r' || c == '\v' || c == '\n')){
|
|
|
|
result = false;
|
|
|
|
goto double_break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
still_looping = forward_stream_chunk(&stream);
|
|
|
|
}while(still_looping);
|
|
|
|
}
|
|
|
|
double_break:;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
static int32_t
|
2017-11-28 20:16:53 +00:00
|
|
|
buffer_get_line_number(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
|
2017-11-28 23:31:10 +00:00
|
|
|
Partial_Cursor partial_cursor = {0};
|
2017-01-23 06:19:43 +00:00
|
|
|
buffer_compute_cursor(app, buffer, seek_pos(pos), &partial_cursor);
|
|
|
|
return(partial_cursor.line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cpp_Token*
|
2017-03-23 19:16:39 +00:00
|
|
|
get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, int32_t *line_start_out = 0){
|
2017-03-23 19:15:33 +00:00
|
|
|
int32_t line_start = buffer_get_line_start(app, buffer, line);
|
2017-03-23 19:16:39 +00:00
|
|
|
Cpp_Get_Token_Result get_token = cpp_get_token(tokens, line_start);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2017-03-23 19:16:39 +00:00
|
|
|
if (get_token.in_whitespace){
|
|
|
|
get_token.token_index += 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
if (line_start_out){
|
2017-01-23 06:19:43 +00:00
|
|
|
*line_start_out = line_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cpp_Token *result = 0;
|
2017-03-23 19:16:39 +00:00
|
|
|
if (get_token.token_index < tokens.count){
|
2017-11-28 20:16:53 +00:00
|
|
|
result = &tokens.tokens[get_token.token_index];
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
static String
|
|
|
|
read_identifier_at_pos(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char *space, int32_t max, Range *range_out){
|
|
|
|
String query = {0};
|
|
|
|
|
|
|
|
int32_t start = buffer_seek_alphanumeric_or_underscore_left(app, buffer, pos);
|
|
|
|
int32_t end = buffer_seek_alphanumeric_or_underscore_right(app, buffer, start);
|
|
|
|
|
|
|
|
if (!(start <= pos && pos < end)){
|
|
|
|
end = buffer_seek_alphanumeric_or_underscore_right(app, buffer, pos);
|
|
|
|
start = buffer_seek_alphanumeric_or_underscore_left(app, buffer, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start <= pos && pos < end){
|
|
|
|
int32_t size = end - start;
|
|
|
|
if (size <= max){
|
|
|
|
if (range_out != 0){
|
|
|
|
*range_out = make_range(start, end);
|
|
|
|
}
|
|
|
|
buffer_read_range(app, buffer, start, end, space);
|
|
|
|
query = make_string_cap(space, size, max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(query);
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|