Method: Rugged::Blob#loc
- Defined in:
- ext/rugged/rugged_blob.c
#loc ⇒ Integer
Return the number of lines for this blob, assuming the blob is plaintext (i.e. not binary)
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'ext/rugged/rugged_blob.c', line 303
static VALUE rb_git_blob_loc(VALUE self)
{
git_blob *blob;
const char *data, *data_end;
size_t loc = 0;
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
data = git_blob_rawcontent(blob);
data_end = data + git_blob_rawsize(blob);
if (data == data_end)
return INT2FIX(0);
for (; data < data_end; ++data) {
if (data[0] == '\n') {
loc++;
}
else if (data[0] == '\r') {
if (data + 1 < data_end && data[1] == '\n')
data++;
loc++;
}
}
if (data[-1] != '\n' && data[-1] != '\r')
loc++;
return INT2FIX(loc);
}
|