KiCad PCB EDA Suite
attenuators.cpp File Reference
#include <wx/wx.h>
#include <dialog_helpers.h>
#include "pcb_calculator_frame.h"

Go to the source code of this file.

Functions

double DoubleFromString (const wxString &TextValue)
 

Function Documentation

◆ DoubleFromString()

double DoubleFromString ( const wxString &  TextValue)

Definition at line 36 of file params_read_write.cpp.

37 {
38  double value = 0;
39 
40  /* Acquire the 'right' decimal point separator */
41  const struct lconv* lc = localeconv();
42  wxChar decimal_point = lc->decimal_point[0];
43  wxString buf( TextValue.Strip( wxString::both ) );
44 
45  /* Convert the period in decimal point */
46  buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
47  // An ugly fix needed by WxWidgets 2.9.1 that sometimes
48  // back to a point as separator, although the separator is the comma
49  buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
50 
51  /* Find the end of the numeric part
52  *(when units are append to the number, remove them)
53  */
54  unsigned brk_point = 0;
55  while( brk_point < buf.Len() )
56  {
57  wxChar ch = buf[brk_point];
58  if( !( ( ch >= '0' && ch <= '9' ) || ( ch == decimal_point ) || ( ch == '-' )
59  || ( ch == '+' ) || ( ch == 'e' ) || ( ch == 'E' ) ) )
60  {
61  break;
62  }
63  ++brk_point;
64  }
65 
66  // Check for strings that cannot qualify as a number
67  if( brk_point == 0 )
68  {
69  return std::nan( "" );
70  }
71 
72  /* Extract the numeric part */
73  if( !buf.Left( brk_point ).ToDouble( &value ) )
74  {
75  return std::nan( "" );
76  }
77  return value;
78 }

Referenced by PCB_CALCULATOR_FRAME::OnCalculateESeries(), PCB_CALCULATOR_FRAME::OnTWCalculateFromCurrent(), PCB_CALCULATOR_FRAME::OnTWCalculateFromExtWidth(), PCB_CALCULATOR_FRAME::OnTWCalculateFromIntWidth(), PCB_CALCULATOR_FRAME::TransfPanelDataToAttenuator(), and PCB_CALCULATOR_FRAME::TWDisplayValues().