check if a line is a code fence; return the * end of the code fence. if passed, width of * the fence rule and character will be returned */
| 1390 | * end of the code fence. if passed, width of |
| 1391 | * the fence rule and character will be returned */ |
| 1392 | static size_t |
| 1393 | is_codefence(uint8_t *data, size_t size, size_t *width, uint8_t *chr) |
| 1394 | { |
| 1395 | size_t i = 0, n = 1; |
| 1396 | uint8_t c; |
| 1397 | |
| 1398 | /* skipping initial spaces */ |
| 1399 | if (size < 3) |
| 1400 | return 0; |
| 1401 | |
| 1402 | if (data[0] == ' ') { i++; |
| 1403 | if (data[1] == ' ') { i++; |
| 1404 | if (data[2] == ' ') { i++; } } } |
| 1405 | |
| 1406 | /* looking at the hrule uint8_t */ |
| 1407 | c = data[i]; |
| 1408 | if (i + 2 >= size || !(c=='~' || c=='`')) |
| 1409 | return 0; |
| 1410 | |
| 1411 | /* the fence must be that same character */ |
| 1412 | while (++i < size && data[i] == c) |
| 1413 | ++n; |
| 1414 | |
| 1415 | if (n < 3) |
| 1416 | return 0; |
| 1417 | |
| 1418 | if (width) *width = n; |
| 1419 | if (chr) *chr = c; |
| 1420 | return i; |
| 1421 | } |
| 1422 | |
| 1423 | /* expects single line, checks if it's a codefence and extracts language */ |
| 1424 | static size_t |
no outgoing calls
no test coverage detected