Class: BibTeX

Inherits:
Object
  • Object
show all
Defined in:
lib/btparse-ruby/BibTeX.rb,
ext/btparse-ruby/btparse_ruby.c

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



2
3
4
# File 'lib/btparse-ruby/BibTeX.rb', line 2

def entries
  @entries
end

Class Method Details

.parse(rb_entry_text) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'ext/btparse-ruby/btparse_ruby.c', line 62

static VALUE bibtex_parse(VALUE klass, VALUE rb_entry_text)
{
  Check_Type(rb_entry_text, T_STRING);

  char *entry_text  = RSTRING_PTR(rb_entry_text);
  boolean status  = 0;

  bt_initialize();

  AST *entries = bt_parse_entry_s(entry_text, NULL, 1, 0, &status);

  /* Exit early if parsing failed */
  if (entries == NULL || status == 0)
  {
    return Qnil;
  }
  
  VALUE rb_entries = ast_to_class(entries);
  
  bt_parse_entry_s(NULL, NULL, 1, 0, NULL);
  
  bt_cleanup();
  
  return rb_entries;
}

.parse_author(rb_string) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'ext/btparse-ruby/btparse_ruby.c', line 113

static VALUE bibtex_parse_author(VALUE klass, VALUE rb_string)
{
  Check_Type(rb_string, T_STRING);

  bt_initialize();

  bt_stringlist *authors = bt_split_list(RSTRING_PTR(rb_string), "and", NULL, 1, "authors");

  VALUE rb_authors = rb_ary_new();

  for (int i = 0; i < authors->num_items; i++) {
    char *author = authors->items[i];

    VALUE rb_author = rb_str_new2(author);

    rb_ary_push(rb_authors, rb_author);
  }

  bt_free_list(authors);

  bt_cleanup();

  return rb_authors;
}

.parse_file(rb_filename) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'ext/btparse-ruby/btparse_ruby.c', line 88

static VALUE bibtex_parse_file(VALUE klass, VALUE rb_filename)
{
  Check_Type(rb_filename, T_STRING);

  char *filename  = RSTRING_PTR(rb_filename);
  boolean status  = 0;

  bt_initialize();

  AST *entries = bt_parse_file(filename, 0, &status);

  /* Exit early if parsing failed */
  if (entries == NULL || status == 0)
  {
    return Qnil;
  }

  VALUE rb_entries = ast_to_class(entries);

  bt_cleanup();

  return rb_entries;
}

.purify(rb_string) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/btparse-ruby/btparse_ruby.c', line 138

static VALUE bibtex_purify(VALUE klass, VALUE rb_string)
{
  Check_Type(rb_string, T_STRING);
  
  bt_initialize();
  
  char *string = malloc(RSTRING_LEN(rb_string) + 1);

  strcpy(string, RSTRING_PTR(rb_string));
  bt_purify_string(string, 0);

  bt_cleanup();

  return rb_str_new2(string);
}