Ver código fonte

Replace broken log2 function; add a missing comment.

tags/v0.2
Ben 11 anos atrás
pai
commit
a689467577
2 arquivos alterados com 14 adições e 3 exclusões
  1. +13
    -3
      mwparserfromhell/parser/tokenizer.c
  2. +1
    -0
      mwparserfromhell/parser/tokenizer.h

+ 13
- 3
mwparserfromhell/parser/tokenizer.c Ver arquivo

@@ -23,9 +23,16 @@ SOFTWARE.

#include "tokenizer.h"

double log2(double n)
/*
Given a context, return the heading level encoded within it.
*/
static int heading_level_from_context(int n)
{
return log(n) / log(2);
int level;
n /= LC_HEADING_LEVEL_1;
for (level = 1; n > 1; n >>= 1)
level++;
return level;
}

static PyObject*
@@ -175,6 +182,9 @@ Tokenizer_push_textbuffer(Tokenizer* self)
return 0;
}

/*
Pop and deallocate the top token stack/context/textbuffer.
*/
static void
Tokenizer_delete_top_of_stack(Tokenizer* self)
{
@@ -858,7 +868,7 @@ Tokenizer_handle_heading_end(Tokenizer* self)
best++;
self->head++;
}
current = log2(self->topstack->context / LC_HEADING_LEVEL_1) + 1;
current = heading_level_from_context(self->topstack->context);
level = current > best ? (best > 6 ? 6 : best) :
(current > 6 ? 6 : current);
after = (HeadingData*) Tokenizer_parse(self, self->topstack->context);


+ 1
- 0
mwparserfromhell/parser/tokenizer.h Ver arquivo

@@ -181,6 +181,7 @@ typedef struct {

/* Function prototypes: */

static int heading_level_from_context(int);
static PyObject* Tokenizer_new(PyTypeObject*, PyObject*, PyObject*);
static struct Textbuffer* Textbuffer_new(void);
static void Tokenizer_dealloc(Tokenizer*);


Carregando…
Cancelar
Salvar