Leaked source code of windows server 2003
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.

558 lines
13 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. LOCSTR.INL
  5. History:
  6. --*/
  7. // Inline functions for the CLocString object. This file is included by
  8. // locstr.h, and should never be used directly.
  9. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10. //
  11. // Return the 'generic' type of the string.
  12. //
  13. //-----------------------------------------------------------------------------
  14. inline
  15. CST::StringType
  16. CLocString::GetStringType(void)
  17. const
  18. {
  19. if (!m_pasBaseString.IsNull())
  20. {
  21. return m_stStringType;
  22. }
  23. else
  24. {
  25. return CST::None;
  26. }
  27. }
  28. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  29. //
  30. // Returns the 'Base' string. This is the localizable string,
  31. // It is the part that weighs most heavily in auto-translation.
  32. //
  33. //-----------------------------------------------------------------------------
  34. inline
  35. const CPascalString &
  36. CLocString::GetString(void)
  37. const
  38. {
  39. return m_pasBaseString;
  40. }
  41. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  42. //
  43. // Get the code page type for the string.
  44. //
  45. //-----------------------------------------------------------------------------
  46. inline
  47. CodePageType
  48. CLocString::GetCodePageType(void)
  49. const
  50. {
  51. return m_cptCodePageType;
  52. }
  53. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  54. //
  55. // TODO - comment this function
  56. //
  57. //-----------------------------------------------------------------------------
  58. inline
  59. const CPascalString &
  60. CLocString::GetNote(void)
  61. const
  62. {
  63. return m_pstrNote;
  64. }
  65. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  66. //
  67. // Sets the string type. The parser and database are the only people who
  68. // should be setting this.
  69. //
  70. //-----------------------------------------------------------------------------
  71. inline
  72. void
  73. CLocString::SetStringType(
  74. CST::StringType newType)
  75. {
  76. m_stStringType = newType;
  77. }
  78. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79. //
  80. // Sets the 'Base' string.
  81. //
  82. // This method can throw the following exceptions:
  83. // CMemoryException
  84. //
  85. //-----------------------------------------------------------------------------
  86. inline
  87. void
  88. CLocString::SetString(
  89. const CPascalString &pstrNewBaseString)
  90. {
  91. m_pasBaseString = pstrNewBaseString;
  92. }
  93. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  94. //
  95. // Sets the code page type for the string.
  96. //
  97. //-----------------------------------------------------------------------------
  98. inline
  99. void
  100. CLocString::SetCodePageType(
  101. CodePageType cptNew)
  102. {
  103. m_cptCodePageType = cptNew;
  104. }
  105. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  106. //
  107. // Clears out the hot-key to an uninitialized state.
  108. //
  109. //-----------------------------------------------------------------------------
  110. inline
  111. void
  112. CLocString::ClearHotKey(void)
  113. {
  114. m_wchHotKeyChar = L'\0';
  115. m_uiHotKeyPos = 0;
  116. }
  117. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  118. //
  119. // TODO - comment this function
  120. //
  121. //-----------------------------------------------------------------------------
  122. inline
  123. void
  124. CLocString::SetNote(
  125. const CPascalString &pstrNote)
  126. {
  127. m_pstrNote = pstrNote;
  128. }
  129. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  130. //
  131. // See if the hotkey has any info in it. Checks to see if the hotkey is
  132. // a valid character (ie non-zero).
  133. //
  134. //-----------------------------------------------------------------------------
  135. inline
  136. BOOL // TRUE if it contains a hotkey
  137. CLocString::HasHotKey(void)
  138. const
  139. {
  140. return (m_wchHotKeyChar != L'\0');
  141. }
  142. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143. //
  144. // Returns the hot-key character. If the hot-key is not initialized, this
  145. // returns NUL.
  146. //
  147. //-----------------------------------------------------------------------------
  148. inline
  149. WCHAR // Hot key character.
  150. CLocString::GetHotKeyChar(void)
  151. const
  152. {
  153. return m_wchHotKeyChar;
  154. }
  155. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  156. //
  157. // Returns the hot-key position. Interpretationb of the position is left up
  158. // to the caller. If the hot-key is uninitialized, this returns 0.
  159. //
  160. //-----------------------------------------------------------------------------
  161. inline
  162. UINT // Position of the hot key.
  163. CLocString::GetHotKeyPos(void)
  164. const
  165. {
  166. return m_uiHotKeyPos;
  167. }
  168. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  169. //
  170. // Sets the hot-key character
  171. //
  172. //-----------------------------------------------------------------------------
  173. inline
  174. void
  175. CLocString::SetHotKeyChar(
  176. WCHAR wchNewHotKeyChar) // Character to set as hot key.
  177. {
  178. m_wchHotKeyChar = wchNewHotKeyChar;
  179. }
  180. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  181. //
  182. // Sets the position of the hot-key
  183. //
  184. //-----------------------------------------------------------------------------
  185. inline
  186. void
  187. CLocString::SetHotKeyPos(
  188. UINT uiNewHotKeyPos) // Position for the hot-key.
  189. {
  190. m_uiHotKeyPos = uiNewHotKeyPos;
  191. }
  192. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  193. //
  194. // Assignment operator for LocStrings.
  195. //
  196. //-----------------------------------------------------------------------------
  197. inline
  198. const CLocString &
  199. CLocString::operator=(
  200. const CLocString &lsSource)
  201. {
  202. CopyLocString(lsSource);
  203. return *this;
  204. }
  205. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  206. //
  207. // Operator == version of IsEqualTo
  208. //
  209. //-----------------------------------------------------------------------------
  210. inline
  211. int // TRUE (1) if equal
  212. CLocString::operator==(
  213. const CLocString &lsOtherString) // String to compare
  214. const
  215. {
  216. return ((((HasHotKey() && lsOtherString.HasHotKey()) &&
  217. (GetHotKeyChar() == lsOtherString.GetHotKeyChar()) &&
  218. (GetHotKeyPos() == lsOtherString.GetHotKeyPos())) ||
  219. (!HasHotKey() && !lsOtherString.HasHotKey())) &&
  220. m_pasBaseString == lsOtherString.m_pasBaseString);
  221. }
  222. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  223. //
  224. // Operator == version of IsEqualTo
  225. //
  226. //-----------------------------------------------------------------------------
  227. inline
  228. int // TRUE (1) if equal
  229. CLocString::operator!=(
  230. const CLocString &lsOtherString) // String to compare
  231. const
  232. {
  233. return !(operator==(lsOtherString));
  234. }
  235. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  236. //
  237. // Constructor for the Translation Object. Just sets the components to
  238. // default bad values.
  239. //
  240. //-----------------------------------------------------------------------------
  241. inline
  242. CLocTranslation::CLocTranslation()
  243. {
  244. m_lidSource = BAD_LOCALE;
  245. m_lidTarget = BAD_LOCALE;
  246. m_uiRanking = 0;
  247. }
  248. //-----------------------------------------------------------------------------
  249. //
  250. // Implementation for copying a translation.
  251. //
  252. //-----------------------------------------------------------------------------
  253. inline
  254. void
  255. CLocTranslation::CopyTranslation(
  256. const CLocTranslation &Source)
  257. {
  258. m_lsSource = Source.m_lsSource;
  259. m_lidSource = Source.m_lidSource;
  260. m_lsTarget = Source.m_lsTarget;
  261. m_lidTarget = Source.m_lidTarget;
  262. m_pstrGlossaryNote = Source.m_pstrGlossaryNote;
  263. m_uiRanking = Source.m_uiRanking;
  264. }
  265. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  266. //
  267. // Copy constructor for a CLocTranslation
  268. //
  269. //-----------------------------------------------------------------------------
  270. inline
  271. CLocTranslation::CLocTranslation(
  272. const CLocTranslation &Source)
  273. {
  274. CopyTranslation(Source);
  275. }
  276. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  277. //
  278. // Sets all the required components of a translation.
  279. //
  280. //-----------------------------------------------------------------------------
  281. inline
  282. void
  283. CLocTranslation::SetTranslation(
  284. const CLocString &Source,
  285. LangId lidSource,
  286. const CLocString &Target,
  287. LangId lidTarget)
  288. {
  289. m_lsSource = Source;
  290. m_lidSource = lidSource;
  291. m_lsTarget = Target;
  292. m_lidTarget = lidTarget;
  293. }
  294. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  295. //
  296. // Sets the glossary note for the translation.
  297. //
  298. //-----------------------------------------------------------------------------
  299. inline
  300. void
  301. CLocTranslation::SetNote(
  302. const CPascalString &pstrNote)
  303. {
  304. m_pstrGlossaryNote = pstrNote;
  305. }
  306. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  307. //
  308. // Constructor for the translation that takes all the required info.
  309. //
  310. //-----------------------------------------------------------------------------
  311. inline
  312. CLocTranslation::CLocTranslation(
  313. const CLocString &Source,
  314. LangId lidSource,
  315. const CLocString &Target,
  316. LangId lidTarget)
  317. {
  318. SetTranslation(Source, lidSource, Target, lidTarget);
  319. }
  320. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  321. //
  322. // Operator == version of IsEqualTo
  323. //
  324. //-----------------------------------------------------------------------------
  325. inline
  326. int
  327. CLocTranslation::operator==(const CLocTranslation &locTran) const
  328. {
  329. return (
  330. GetSourceString() == locTran.GetSourceString()
  331. && GetSourceString().GetStringType()
  332. == locTran.GetSourceString().GetStringType()
  333. && GetTargetString() == locTran.GetTargetString()
  334. && GetTargetString().GetStringType()
  335. == locTran.GetTargetString().GetStringType()
  336. && GetNote() == locTran.GetNote()
  337. && GetRanking() == locTran.GetRanking()
  338. );
  339. }
  340. inline
  341. int
  342. CLocTranslation::operator!=(const CLocTranslation &locTran) const
  343. {
  344. return !(operator==(locTran));
  345. }
  346. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  347. //
  348. // Returns the source string of the translation.
  349. //
  350. //-----------------------------------------------------------------------------
  351. inline
  352. const CLocString &
  353. CLocTranslation::GetSourceString(void)
  354. const
  355. {
  356. return m_lsSource;
  357. }
  358. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  359. //
  360. // Returns the target string for the translation.
  361. //
  362. //-----------------------------------------------------------------------------
  363. inline
  364. const CLocString &
  365. CLocTranslation::GetTargetString(void)
  366. const
  367. {
  368. return m_lsTarget;
  369. }
  370. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  371. //
  372. // Returns the glkossary note for the translation.
  373. //
  374. //-----------------------------------------------------------------------------
  375. inline
  376. const CPascalString &
  377. CLocTranslation::GetNote(void)
  378. const
  379. {
  380. return m_pstrGlossaryNote;
  381. }
  382. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  383. //
  384. // Returns the translation ranking for the strnslation. See
  385. // CalculateRanking().
  386. //
  387. //-----------------------------------------------------------------------------
  388. inline
  389. UINT
  390. CLocTranslation::GetRanking(void)
  391. const
  392. {
  393. return m_uiRanking;
  394. }
  395. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  396. //
  397. // Returns the embedded source language for the translation.
  398. //
  399. //-----------------------------------------------------------------------------
  400. inline
  401. LangId
  402. CLocTranslation::GetSourceLanguage(void)
  403. const
  404. {
  405. return m_lidSource;
  406. }
  407. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  408. //
  409. // Returns the embedded target language for the translation.
  410. //
  411. //-----------------------------------------------------------------------------
  412. inline
  413. LangId
  414. CLocTranslation::GetTargetLanguage(void)
  415. const
  416. {
  417. return m_lidTarget;
  418. }
  419. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  420. //
  421. // Validates the translation. This make sure that all the needed components
  422. // of tghe source string exist in some form in the target string. This
  423. // simply returns a validation code.
  424. //
  425. //-----------------------------------------------------------------------------
  426. inline
  427. CVC::ValidationCode
  428. CLocTranslation::ValidateTranslation(
  429. const CValidationOptions &Options)
  430. const
  431. {
  432. CLString str;
  433. return ValidateTranslation(Options, FALSE, str, NULL, NULL);
  434. }
  435. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  436. //
  437. // Assignment operator for the translation object.
  438. //
  439. //-----------------------------------------------------------------------------
  440. inline
  441. const CLocTranslation &
  442. CLocTranslation::operator=(
  443. const CLocTranslation &Source) // Translation to copy from.
  444. {
  445. CopyTranslation(Source);
  446. return *this;
  447. }
  448. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  449. //
  450. // Destructor for the translation. Nothing interesting happens here.
  451. //
  452. //-----------------------------------------------------------------------------
  453. inline
  454. CLocTranslation::~CLocTranslation()
  455. {
  456. DEBUGONLY(AssertValid());
  457. }