is_hrule • returns whether a line is a horizontal rule */
| 1357 | |
| 1358 | /* is_hrule • returns whether a line is a horizontal rule */ |
| 1359 | static int |
| 1360 | is_hrule(uint8_t *data, size_t size) |
| 1361 | { |
| 1362 | size_t i = 0, n = 0; |
| 1363 | uint8_t c; |
| 1364 | |
| 1365 | /* skipping initial spaces */ |
| 1366 | if (size < 3) return 0; |
| 1367 | if (data[0] == ' ') { i++; |
| 1368 | if (data[1] == ' ') { i++; |
| 1369 | if (data[2] == ' ') { i++; } } } |
| 1370 | |
| 1371 | /* looking at the hrule uint8_t */ |
| 1372 | if (i + 2 >= size |
| 1373 | || (data[i] != '*' && data[i] != '-' && data[i] != '_')) |
| 1374 | return 0; |
| 1375 | c = data[i]; |
| 1376 | |
| 1377 | /* the whole line must be the char or space */ |
| 1378 | while (i < size && data[i] != '\n') { |
| 1379 | if (data[i] == c) n++; |
| 1380 | else if (data[i] != ' ') |
| 1381 | return 0; |
| 1382 | |
| 1383 | i++; |
| 1384 | } |
| 1385 | |
| 1386 | return n >= 3; |
| 1387 | } |
| 1388 | |
| 1389 | /* check if a line is a code fence; return the |
| 1390 | * end of the code fence. if passed, width of |
no outgoing calls
no test coverage detected