Audio plugin host https://kx.studio/carla
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.

ysfx_reader.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2021 Jean Pierre Cimalando
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // SPDX-License-Identifier: Apache-2.0
  16. //
  17. #include "ysfx_reader.hpp"
  18. namespace ysfx {
  19. //------------------------------------------------------------------------------
  20. bool text_reader::read_next_line(std::string &line)
  21. {
  22. line.clear();
  23. char next = read_next_char();
  24. if (next == '\0')
  25. return false;
  26. while (next != '\0' && next != '\r' && next != '\n') {
  27. line.push_back(next);
  28. next = read_next_char();
  29. }
  30. if (next == '\r') {
  31. next = peek_next_char();
  32. if (next == '\n')
  33. read_next_char();
  34. }
  35. return true;
  36. }
  37. //------------------------------------------------------------------------------
  38. char string_text_reader::read_next_char()
  39. {
  40. const char *ptr = m_char_ptr;
  41. if (!ptr || *ptr == '\0')
  42. return '\0';
  43. char next = *ptr;
  44. m_char_ptr = ptr + 1;
  45. return next;
  46. }
  47. char string_text_reader::peek_next_char()
  48. {
  49. const char *ptr = m_char_ptr;
  50. if (!ptr)
  51. return '\0';
  52. return *ptr;
  53. }
  54. //------------------------------------------------------------------------------
  55. char stdio_text_reader::read_next_char()
  56. {
  57. FILE *stream = m_stream;
  58. if (!stream)
  59. return '\0';
  60. int next = fgetc(stream);
  61. if (next == EOF)
  62. return '\0';
  63. return (unsigned char)next;
  64. }
  65. char stdio_text_reader::peek_next_char()
  66. {
  67. FILE *stream = m_stream;
  68. if (!stream)
  69. return '\0';
  70. int next = fgetc(stream);
  71. if (next == EOF)
  72. return '\0';
  73. ungetc(next, stream);
  74. return (unsigned char)next;
  75. }
  76. } // namespace ysfx