Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preprocess.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use strict'
  2. var search = /[\0\t\n\r]/g
  3. function preprocess() {
  4. var start = true
  5. var column = 1
  6. var buffer = ''
  7. var atCarriageReturn
  8. return preprocessor
  9. function preprocessor(value, encoding, end) {
  10. var chunks = []
  11. var match
  12. var next
  13. var startPosition
  14. var endPosition
  15. var code
  16. value = buffer + value.toString(encoding)
  17. startPosition = 0
  18. buffer = ''
  19. if (start) {
  20. if (value.charCodeAt(0) === 65279) {
  21. startPosition++
  22. }
  23. start = undefined
  24. }
  25. while (startPosition < value.length) {
  26. search.lastIndex = startPosition
  27. match = search.exec(value)
  28. endPosition = match ? match.index : value.length
  29. code = value.charCodeAt(endPosition)
  30. if (!match) {
  31. buffer = value.slice(startPosition)
  32. break
  33. }
  34. if (code === 10 && startPosition === endPosition && atCarriageReturn) {
  35. chunks.push(-3)
  36. atCarriageReturn = undefined
  37. } else {
  38. if (atCarriageReturn) {
  39. chunks.push(-5)
  40. atCarriageReturn = undefined
  41. }
  42. if (startPosition < endPosition) {
  43. chunks.push(value.slice(startPosition, endPosition))
  44. column += endPosition - startPosition
  45. }
  46. if (code === 0) {
  47. chunks.push(65533)
  48. column++
  49. } else if (code === 9) {
  50. next = Math.ceil(column / 4) * 4
  51. chunks.push(-2)
  52. while (column++ < next) chunks.push(-1)
  53. } else if (code === 10) {
  54. chunks.push(-4)
  55. column = 1
  56. } // Must be carriage return.
  57. else {
  58. atCarriageReturn = true
  59. column = 1
  60. }
  61. }
  62. startPosition = endPosition + 1
  63. }
  64. if (end) {
  65. if (atCarriageReturn) chunks.push(-5)
  66. if (buffer) chunks.push(buffer)
  67. chunks.push(null)
  68. }
  69. return chunks
  70. }
  71. }
  72. module.exports = preprocess