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.

55 lines
1.8 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <text_utils.h>
  25. std::pair<UTF8, std::vector<bool>> ProcessOverbars( const UTF8& aText )
  26. {
  27. UTF8 text;
  28. std::vector<bool> flags;
  29. bool overbar = false;
  30. for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
  31. {
  32. if( *chIt == '~' )
  33. {
  34. if( ++chIt >= end )
  35. break;
  36. // It was a single tilda, it toggles overbar
  37. if( *chIt != '~' )
  38. overbar = !overbar;
  39. // If it is a double tilda, just process the second one
  40. }
  41. // remember: *chIt is not necessary a ASCII7 char.
  42. // it is an unsigned giving a multibyte char in UTF8 strings
  43. text += *chIt;
  44. flags.push_back( overbar );
  45. }
  46. return std::make_pair( text, flags );
  47. }